/bs-react-intl-extractor

Extracts messages for localization from Reason source files.

Primary LanguageReasonMIT LicenseMIT

bs-react-intl-extractor

Extracts messages for localization from Reason source files. This assumes that you are using the bs-react-intl bindings for react-intl.

NPM
Build Status

Installation

Binaries for macOS and Linux can be installed via npm or yarn. For global installation, run

npm install -g bs-react-intl-extractor-bin

Alternatively, the binaries are also available for download on the releases page.

Usage

bs-react-intl-extractor [--allow-duplicates] [path...]

where path is a Reason source file or a directory containing Reason source files. Multiple files/directories may be specified.

The --allow-duplicates option allows messages with identical id props if the defaultMessage props are identical as well.

Formatted messages may be defined in your source files in one of the following three ways:

  1. inline in FormattedMessage:
<ReactIntl.FormattedMessage id="some.message.id" defaultMessage="Some message" />

or

open ReactIntl;
...
<FormattedMessage id="some.message.id" defaultMessage="Some message" />
  1. using ReactIntl.defineMessages:
let messages =
  ReactIntl.defineMessages(. {
    "hello": {
      "id": "message.hello",
      "defaultMessage": "Hello",
    },
    "world": {
      "id": "message.world",
      "defaultMessage": "World",
    },
  });

or

open ReactIntl;
...
let messages =
  defineMessages(. {
    "hello": {
      "id": "message.hello",
      "defaultMessage": "Hello",
    },
    "world": {
      "id": "message.world",
      "defaultMessage": "World",
    },
  });
  1. using the attribute [@intl.messages]:
let messages =
  [@intl.messages]
  {
    "hello": {
      "id": "message.hello",
      "defaultMessage": "Hello",
    },
    "world": {
      "id": "message.world",
      "defaultMessage": "World",
    },
  };

The output (a JSON array of all extracted messages sorted by id) is written to stdout. It will look like this:

[
  {
    "id": "message.hello",
    "defaultMessage": "Hello"
  },
  {
    "id": "message.world",
    "defaultMessage": "World"
  },
  {
    "id": "some.message.id",
    "defaultMessage": "Some message"
  }
]

Building and Testing

Install esy as follows:

% npm install -g esy@latest

Then you can install the project dependencies using:

% esy install

Then build the project dependencies along with the project itself:

% esy build

Run the compiled executable:

% esy x Extract.exe

Run the tests:

% esy x Test.exe