Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@formatjs/cli
Advanced tools
@formatjs/cli is a command-line tool for internationalizing JavaScript applications. It provides functionalities for extracting, compiling, and managing translation messages, making it easier to handle localization in your projects.
Extract Messages
This command extracts all the translation messages from the JavaScript files in the 'src' directory and outputs them to a JSON file named 'en.json'.
npx formatjs extract 'src/**/*.js' --out-file lang/en.json
Compile Messages
This command compiles the extracted messages from 'en.json' into a format that can be used by the application, outputting the result to 'en-compiled.json'.
npx formatjs compile lang/en.json --out-file lang/en-compiled.json
Compile Messages with Pseudo-Localization
This command compiles the messages with pseudo-localization, which is useful for testing how the application handles different languages and character sets. The output is saved to 'en-pseudo.json'.
npx formatjs compile lang/en.json --pseudo-locale --out-file lang/en-pseudo.json
Format Messages
This command formats the extracted messages in 'en.json' to ensure consistency and readability, saving the formatted messages to 'en-formatted.json'.
npx formatjs format lang/en.json --out-file lang/en-formatted.json
i18next is a popular internationalization framework for JavaScript. It provides a complete solution for localizing your application, including features for translation management, language detection, and interpolation. Compared to @formatjs/cli, i18next offers a more comprehensive set of tools for managing translations and supports a wider range of use cases.
react-intl is a library for internationalizing React applications. It provides React components and an API for formatting dates, numbers, and strings, as well as handling pluralization and gender-specific messages. While @formatjs/cli focuses on command-line tools for managing translations, react-intl integrates directly with React to provide runtime localization support.
formatjs-cli
This CLI allows you to extract intl-messageformat
messages from JavaScript / TypeScript source code,
including React components that uses react-intl
.
$ npm -g i @formatjs/cli
$ formatjs extract --help
Usage: formatjs extract [options] [files...]
Extract string messages from React components that use react-intl.
The input language is expected to be TypeScript or ES2017 with JSX.
Options:
--messages-dir <dir> The target location where the plugin will output a `.json` file
corresponding to each component from which React Intl messages
were extracted. If not provided, the extracted message
descriptors will be printed to standard output.
--extract-source-location Whether the metadata about the location of the message in the
source file should be extracted. If `true`, then `file`,
`start`, and `end` fields will exist for each extracted message
descriptors. (default: false)
--module-source-name <name> The ES6 module source name of the React Intl package. Defaults
to: `"react-intl"`, but can be changed to another name/path to
React Intl.
--remove-default-message Remove `defaultMessage` field in generated js after extraction
(default: false)
--additional-component-names <comma-separated-names> Additional component names to extract messages from, e.g:
`['FormattedFooBarMessage']`. **NOTE**: By default we check for
the fact that `FormattedMessage` & `FormattedHTMLMessage` are
imported from `moduleSourceName` to make sure variable alias
works. This option does not do that so it's less safe.
--extract-from-format-message-call Opt-in to extract from `intl.formatMessage` call with the same
restrictions, e.g: has to be called with object literal such as
`intl.formatMessage({ id: 'foo', defaultMessage: 'bar',
description: 'baz'})` (default: false)
-h, --help output usage information
FAQs
A CLI for formatjs.
The npm package @formatjs/cli receives a total of 262,500 weekly downloads. As such, @formatjs/cli popularity was classified as popular.
We found that @formatjs/cli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.