JSPM

@formatjs/cli

1.6.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 379804
  • Score
    100M100P100Q174411F
  • License MIT

A CLI for formatjs.

Package Exports

  • @formatjs/cli

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@formatjs/cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

formatjs-cli

This CLI allows you to extract intl-messageformat messages from JavaScript / TypeScript source code, including React components that uses react-intl.

Usage

$ npm -g i @formatjs/cli
$ formatjs extract --help
Usage: formatjs extract [options] [files...]
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.
  --out-file <path>                                     The target file path where the plugin will output an aggregated `.json` file of allthe translations from the `files` supplied.
                                                        This flag will ignore --messages-dir
  --id-interpolation-pattern <pattern>                  If certain message descriptors don't have id, this `pattern` will be used to automaticallygenerate IDs for them. Default to `[contenthash:5]`.
                                                        See https://github.com/webpack/loader-utils#interpolatename for sample patterns
  --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` is 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)
  --output-empty-json                                   Output file with empty [] if src has no messages. For build systems like bazel that relies on specific output mapping, not writing out a file can cause issues. (default: false)
  --ignore <files>                                      List of glob paths to **not** extract translations from.
  --throws                                              Whether to throw an exception when we fail to process any file in the batch.
  --pragma <pragma>                                     parse specific additional custom pragma. This allows you to tag certain file with metadata such as `project`. For example with this file:

        ```
        // @intl-meta project:my-custom-project
        import {FormattedMessage} from 'react-intl';

        <FormattedMessage defaultMessage="foo" id="bar" />;
        ```

        and with option `{pragma: "@intl-meta"}`, we'll parse out `// @intl-meta project:my-custom-project` into `{project: 'my-custom-project'}` in the result file.
  -h, --help                                            display help for command