Skip to content

Commit cd2a665

Browse files
committed
Update messageformat.js to 1.0.0
1 parent 42d5569 commit cd2a665

3 files changed

Lines changed: 26 additions & 27 deletions

File tree

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ author:
1818
paginate: 5
1919

2020
# Custom vars
21-
version: 0.3.1
21+
version: 1.0.0
2222

2323
npm:
2424
link: https://www.npmjs.com/package/messageformat

build.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,39 @@ Note that as `efunc` is defined as a `new Function()`, it has no access to the s
4040
A [CLI compiler](https://github.com/messageformat/messageformat.js/tree/master/bin/messageformat.js) is also included, available as `./node_modules/.bin/messageformat` or just `messageformat` when installed with `npm install -g`.
4141

4242
```text
43-
$ messageformat --help
44-
Usage: messageformat -l [locale] [OPTIONS] [INPUT_DIR] [OUTPUT_DIR]
45-
46-
Available options:
47-
-l, --locale locale(s) to use [mandatory]
48-
-i, --inputdir directory containing messageformat files to compile
49-
-o, --output output where messageformat will be compiled
50-
-ns, --namespace global object in the output containing the templates
51-
-I, --include glob patterns for files to include from `inputdir`
52-
-m, --module create a commonJS module, instead of a global window variable
53-
-s, --stdout print the result in stdout instead of writing in a file
54-
-w, --watch watch `inputdir` for changes
55-
-v, --verbose print logs for debug
56-
```
57-
58-
`messageformat` will recursively read all JSON files in `inputdir` and compile them to `output`.
59-
60-
When using the CLI, the following commands will each produce the same results as included in the [examples](https://github.com/messageformat/messageformat.js/tree/master/example/en):
61-
62-
```
63-
$ messageformat --locale en --namespace i18n --inputdir ./example/en --output ./i18n.js
64-
$ messageformat --locale en ./example/en ./i18n.js
65-
$ messageformat -l en ./example/en
43+
$ messageformat
44+
usage: messageformat [-l lc] [-n ns] [-p] input
45+
46+
Parses the input JSON file(s) of MessageFormat strings into a JS module of
47+
corresponding hierarchical functions, written to stdout. Directories are
48+
recursively scanned for all .json files.
49+
50+
-l lc, --locale=lc
51+
The locale(s) lc to include; if multiple, selected by matching
52+
message key. [default: en]
53+
54+
-n ns, --namespace=ns
55+
The global object or modules format for the output JS. If ns does not
56+
contain a '.', the output follows an UMD pattern. For module support,
57+
the values 'export default' (ES6), 'exports' (CommonJS), and
58+
'module.exports' (node.js) are special. [default: module.exports]
59+
60+
-p, --disable-plural-key-checks
61+
By default, messageformat.js throws an error when a statement uses a
62+
non-numerical key that will never be matched as a pluralization
63+
category for the current locale. Use this argument to disable the
64+
validation and allow unused plural keys. [default: false]
6665
```
6766

6867

6968
## Using compiled messageformat.js output
7069

71-
With default options, compiled messageformat functions are available through the `i18n` global object, with each source json having a corresponding subobject. Hence the compiled function corresponding to the `test` message defined in [`example/en/sub/folder/plural.json`](https://github.com/messageformat/messageformat.js/tree/master/example/en/sub/folder/plural.json) is available as [`i18n['sub/folder/plural'].plural`](https://github.com/messageformat/messageformat.js/tree/master/example/en/i18n.js):
70+
With default options, compiled messageformat functions are available through `module.exports`. However, using e.g. `-n i18n`, an UMD pattern is used, falling back to a global `i18n` object, with each source json having a corresponding subobject. Hence the compiled function corresponding to the `test` message defined in [`example/en/sub/folder/plural.json`](https://github.com/messageformat/messageformat.js/tree/master/example/en/sub/folder/plural.json) is available as [`i18n.sub.folder.plural.test`](https://github.com/messageformat/messageformat.js/tree/master/example/en/i18n.js):
7271

7372
```html
7473
<script src="path/to/messageformat/example/en/i18n.js"></script>
7574
<script>
76-
console.log(i18n['sub/folder/plural'].plural({NUM: 3}));
75+
console.log(i18n.sub.folder.plural.test({ NUM: 3 }));
7776
</script>
7877
```
7978
will log `"Your 3 messages go here."`

messageformat.js

0 commit comments

Comments
 (0)