What is @lingui/cli?
@lingui/cli is a command-line interface for the LinguiJS framework, which is used for internationalization (i18n) in JavaScript applications. It provides tools for extracting messages, compiling them, and managing translations.
What are @lingui/cli's main functionalities?
Extract Messages
This command scans your source code for messages marked for translation and extracts them into a catalog file. This is useful for identifying all the text that needs to be translated in your application.
lingui extract
Compile Messages
This command compiles the message catalogs into a format that can be used by the application at runtime. This step is necessary to convert the raw translation files into a format that the LinguiJS runtime can understand.
lingui compile
Add Locale
This command adds a new locale to your project. It sets up the necessary files and directories for managing translations in the specified locale.
lingui add-locale [locale]
Extract and Compile
This combined command first extracts messages and then compiles them. It is a convenient way to update your translation catalogs and make them ready for use in your application.
lingui extract && lingui compile
Other packages similar to @lingui/cli
i18next
i18next is a popular internationalization framework for JavaScript. It provides a comprehensive set of tools for managing translations, including a CLI for extracting and compiling messages. Compared to @lingui/cli, i18next offers more flexibility and a larger ecosystem of plugins and extensions.
react-intl
react-intl is a library for internationalizing React applications. It provides components and an API for formatting dates, numbers, and strings, as well as managing translations. While it does not have a dedicated CLI, it integrates well with other tools for extracting and managing translations.
formatjs
formatjs is a set of libraries for internationalizing JavaScript applications. It includes tools for formatting dates, numbers, and strings, as well as managing translations. The formatjs CLI provides similar functionality to @lingui/cli for extracting and compiling messages.
@lingui/cli
lingui command line library for manipulating message catalogues
@lingui/cli
is part of LinguiJS. See the documentation for all information, tutorials and examples.
Installation
The library can be installed globally or locally using yarn
or npm
. The recommended way is installing the package locally. This ensures that everyone who uses the project has the same version and does not need to install additional packages.
npm install --save-dev @lingui/cli
# or using yarn
yarn add --dev @lingui/cli
To run the library locally there are three options, with the first one been recommended one.
1) Add commands to scripts
Add these scripts to your package.json
.
{
"scripts": {
"extract": "lingui extract",
"compile": "lingui compile"
}
}
Then you can use:
npm run extract
npm run compile
2) Use NPX
You can run the scripts directly using a tool for executing Node packages NPX
. NPX
is included in NPM
version 5.2 and higher.
npx lingui extract
npx lingui compile
3) Run commands directly
You can run commands directly from node_modules
folder.
node_modules/.bin/lingui extract
node_modules/.bin/lingui compile
Usage
See the reference documentation.
License
This package is licensed under MIT license.