lingui-i18n
Advanced tools
Comparing version
{ | ||
"name": "lingui-i18n", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "I18n tools for javascript", | ||
@@ -28,3 +28,3 @@ "main": "index.js", | ||
"babel-runtime": "^6.23.0", | ||
"lingui-formats": "^1.0.0", | ||
"lingui-formats": "^1.0.1", | ||
"make-plural": "^4.0.1", | ||
@@ -31,0 +31,0 @@ "messageformat-parser": "^1.0.0" |
@@ -0,13 +1,16 @@ | ||
[![License][Badge-License]][License] | ||
[![Version][Badge-Version]][Package] | ||
[![Downloads][Badge-Downloads]][Package] | ||
# lingui-i18n | ||
> JS API for I18n using ICU message format | ||
> Javascript API for internationalization | ||
`lingui-i18n` provide helpers for writing texts using ICU message format | ||
`lingui-i18n` is part of [js-lingui][jsLingui]. See the [documentation][Documentation] for all information, tutorials and examples. | ||
## Install | ||
## Installation | ||
```sh | ||
npm install --save lingui-i18n | ||
# or | ||
```bash | ||
yarn add lingui-i18n | ||
# npm install --save lingui-i18n | ||
``` | ||
@@ -17,73 +20,16 @@ | ||
Import `i18n` object and load message catalog: | ||
See the [tutorial][Tutorial] or [reference][Reference] documenation. | ||
```js | ||
import { i18n } from 'lingui-i18n' | ||
## License | ||
// Required for development only | ||
i18n.development(require('lingui-i18n/dev')) | ||
[MIT][License] | ||
// load messages | ||
i18n.load({ | ||
fr: { | ||
messages: { | ||
"Hello World!": "Salut le monde!", | ||
"My name is {name}": "Je m'appelle {name}", | ||
"{count, plural, one {# book} other {# books}}": "{count, plural, one {# livre} other {# livres}}" | ||
} | ||
} | ||
}) | ||
// set active language | ||
i18n.use('fr') | ||
``` | ||
Wrap you text in `i18n.t` template literal tag so it's translated into active | ||
language: | ||
```js | ||
i18n.t`Hello World!` | ||
// becomes "Salut le monde!" | ||
const name = "Fred" | ||
i18n.t`My name is ${ name }` | ||
// becomes "Je m'appelle Fred" | ||
``` | ||
Plurals and selections are possible using `plural` and `select` methods: | ||
```js | ||
const count = 42 | ||
i18n.plural({ | ||
value: count, | ||
one: "# book", | ||
other: "# books" | ||
}) | ||
// becomes "42 livres" | ||
``` | ||
It's also possible to nest message formats. Each message format method in `i18n` has a standalone companion, which only returns message without performing the translation: | ||
```js | ||
import { t, plural } from 'lingui-i18n' | ||
// use i18n.select here, to translate message format | ||
i18n.select({ | ||
value: gender, | ||
offset: 1, | ||
// plural, instead of i18n.plural | ||
female: plural({ | ||
value: numOfGuests, | ||
offset: 1, | ||
// t, instead of i18n.t | ||
0: t`${host} does not give a party.`, | ||
1: t`${host} invites ${guest} to her party.`, | ||
2: t`${host} invites ${guest} and one other person to her party.`, | ||
other: t`${host} invites ${guest} and # other people to her party.` | ||
}), | ||
male: plural({...}), | ||
other: plural({...}), | ||
}) | ||
``` | ||
[License]: https://github.com/lingui/js-lingui/blob/master/LICENSE.md | ||
[jsLingui]: https://github.com/lingui/js-lingui | ||
[Documentation]: https://lingui.gitbooks.io/js/ | ||
[Tutorial]: https://lingui.gitbooks.io/js/tutorials/js.html | ||
[Reference]: https://lingui.gitbooks.io/js/ref/js.html | ||
[Package]: https://www.npmjs.com/package/lingui-i18n | ||
[Badge-Downloads]: https://img.shields.io/npm/dw/lingui-i18n.svg | ||
[Badge-Version]: https://img.shields.io/npm/v/lingui-i18n.svg | ||
[Badge-License]: https://img.shields.io/npm/l/lingui-i18n.svg |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13
-45.83%39731
-38.7%22
-43.59%718
-53.16%35
-60.67%Updated