Skip to content

Update docs #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)
Expand All @@ -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.

Expand All @@ -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
<ReactIntl.FormattedMessage id="some.message.id" defaultMessage="Some message" />
```

or

```rescript
open ReactIntl;
...
<FormattedMessage id="some.message.id" defaultMessage="Some message" />
```

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:

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down