Skip to content

Commit 69e2913

Browse files
committed
Update README
1 parent 8241686 commit 69e2913

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

README.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
# Property Resource Bundle Loader for Webpack
22

3-
Loads .properties files into JavaScript as precompiled functions using
4-
[dot-properties] and [messageformat].
3+
Loads .properties files into JavaScript as precompiled functions using [dot-properties] and [messageformat].
54

6-
Property values are parsed directly as ICU MessageFormat. With the default
7-
options, will assume that the filename has `_` separated parts, of which the
8-
second is the two- or three-letter language code [as in Java Resource Bundles](https://docs.oracle.com/javase/9/docs/api/java/util/ResourceBundle.html#getBundle-java.lang.String-java.util.Locale-java.lang.ClassLoader-)
5+
Property values are parsed directly as ICU MessageFormat. With the default options, will assume that the filename has `_` separated parts, of which the second is the two- or three-letter language code [as in Java Resource Bundles].
96

107
[dot-properties]: https://www.npmjs.com/package/dot-properties
118
[messageformat]: https://messageformat.github.io/
9+
[as in Java Resource Bundles]: https://docs.oracle.com/javase/9/docs/api/java/util/ResourceBundle.html#getBundle-java.lang.String-java.util.Locale-java.lang.ClassLoader-
1210

1311
## Installation
1412

1513
```sh
16-
npm install messageformat messageformat-properties-loader
14+
npm install messageformat@next messageformat-properties-loader
1715
```
1816

17+
Starting from version 0.4.0, the loader requires messageformat v3, currently in beta.
18+
1919

2020
## Usage
2121

22-
For a working demo of the following, run `npm install` in the
23-
[`example/`](./example/) directory, and then open `example/dist/index.html` in
24-
a browser.
22+
For a working demo of the following, run `npm install && npm run build` in the [`example/`](./example/) directory, and then open `example/dist/index.html` in a browser.
2523

2624

2725
#### Webpack configuration
2826

2927
```js
3028
{
3129
test: /\.properties$/,
32-
loader: require.resolve('messageformat-properties-loader'),
30+
loader: 'messageformat-properties-loader',
3331
options: {
3432
biDiSupport: false, // enables bi-directional text support
3533
defaultLocale: 'en', // used if resolution from filename fails
@@ -43,32 +41,27 @@ a browser.
4341
}
4442
```
4543

46-
Default option values are shown above, though none is required.
44+
Default option values are shown above, though none are required.
4745

4846

4947
#### messages_en.properties
5048

5149
```
52-
errors.format: {0} {1}
53-
errors.messages.confirmation: doesn't match {attribute}
54-
errors.messages.accepted: must be accepted
55-
errors.messages.wrong_length: is the wrong length (should be {count, plural, one{1 character} other{# characters}})
56-
errors.messages.equal_to: must be equal to {count}
50+
errors.confirmation: {src} doesn't match {attribute}
51+
errors.accepted: {src} must be accepted
52+
errors.wrong_length: {src} is the wrong length (should be {count, plural, one{1 character} other{# characters}})
53+
errors.equal_to: {src} must be equal to {count}
5754
```
5855

5956

6057
#### example.js
6158

6259
```js
6360
import messages from './messages_en.properties'
64-
const { format, messages: errors } = messages.errors
6561

66-
errors.accepted()
67-
// 'must be accepted'
62+
messages.errors.accepted({ src: 'Terms' })
63+
// 'Terms must be accepted'
6864

69-
format([
70-
'Your message',
71-
errors.wrong_length({ count: 42 })
72-
])
73-
// 'Your message is the wrong length (should be 42 characters)'
65+
messages.errors.wrong_length({ src: 'Foo', count: 42 })
66+
// 'Foo is the wrong length (should be 42 characters)'
7467
```

0 commit comments

Comments
 (0)