diff --git a/CHANGELOG.md b/CHANGELOG.md index 10671ac..a5c58b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.10.0 - 2021-01-10 + +- Added ReScript support (ReScript 7cc70c9). 🎉 +- Removed support for bs-react-intl 1.x style message definition. +- Downgraded to OCaml 4.06 to be able to build ReScript parser. + ## 0.9.1 - 2020-11-15 - Added optional description support for message records via `@intl.description` attribute. diff --git a/README.md b/README.md index 13aad53..8985894 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bs-react-intl-extractor -Extracts messages for localization from [Reason] source files. +Extracts messages for localization from [ReScript] or [Reason] source files. This assumes that you are using the [bs-react-intl] 2.x bindings for [react-intl]. [![NPM](https://nodei.co/npm/bs-react-intl-extractor-bin.png?compact=true)](https://nodei.co/npm/bs-react-intl-extractor-bin/) @@ -22,7 +22,7 @@ Alternatively, the binaries are also available for download on the [releases pag 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. +where `path` is a ReScript (`*.res`) or Reason (`*.re`) source file or a directory containing such 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. @@ -47,7 +47,44 @@ The output (a JSON array of all extracted messages sorted by id) is written to s ] ``` -## Message Definition +## Message Definition (ReScript Syntax) + +Formatted messages may be defined in your source files in one of the following ways: + +1. inline in `FormattedMessage`: + +```rescript + +``` + +or + +```rescript +open ReactIntl; +... + +``` + +2. within a module with the `[@intl.messages]` attribute: + +```rescript +open ReactIntl + +module Msg = { + @@intl.messages + + let hello = {id: "message.hello", defaultMessage: "Hello"} + let world = {id: "message.world", defaultMessage: "World"} +} +``` + +You also can pass descriptions to the records with: + +```rescript +let foo = @intl.description("Hello description") {id: "message.hello", defaultMessage: "Hello"} +``` + +## Message Definition (Reason Syntax) Formatted messages may be defined in your source files in one of the following ways: @@ -86,6 +123,10 @@ let foo = [@intl.description "Hello description"] {id: "message.hello", defaultM ## Building and Testing +The ReScript parser is included as a git submodule. Therefore, after checking out the sources, first run + + git submodule update --init --recursive + Install [esy] as follows: % npm install -g esy @@ -106,6 +147,7 @@ Run the tests: % esy test +[rescript]: https://rescript-lang.org/ [reason]: https://reasonml.github.io [bs-react-intl]: https://github.com/alexfedoseev/bs-react-intl [react-intl]: https://github.com/yahoo/react-intl