From 3000b7a3bb481e2ee46380e8b0481fa2e7b60e89 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Wed, 26 Sep 2018 20:07:01 -0700 Subject: [PATCH] Rename Node.js to Vanilla JS and give example of internationalizing a string constant. --- packages/kbn-i18n/README.md | 51 ++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/packages/kbn-i18n/README.md b/packages/kbn-i18n/README.md index 54eadbd46ca9e..2a5abe3e2b1da 100644 --- a/packages/kbn-i18n/README.md +++ b/packages/kbn-i18n/README.md @@ -171,6 +171,37 @@ import memoizeIntlConstructor from 'intl-format-cache'; const getMessageFormat = memoizeIntlConstructor(IntlMessageFormat); ``` +## Vanilla JS + +`Intl-messageformat` package assumes that the +[Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) +global object exists in the runtime. `Intl` is present in all modern +browsers and Node.js 0.10+. In order to load i18n engine +in Node.js we should simply `import` this module (in Node.js, the +[data](https://github.com/yahoo/intl-messageformat/tree/master/dist/locale-data) +for all 200+ languages is loaded along with the library) and pass the translation +messages into `init` method: + +```js +import { i18n } from '@kbn/i18n'; + +i18n.init(messages); +``` + +One common use-case is that of internationalizing a string constant. Here's an +example of how we'd do that: + +```js +import { i18n } from '@kbn/i18n'; + +export const HELLO_WORLD = i18n.translate('hello.wonderful.world', { + defaultMessage: 'Greetings, planet Earth!', +}), +``` + +We're also able to use all methods exposed by the i18n engine +(see [I18n engine](#i18n-engine) section above for more details). + ## React [React-intl](https://github.com/yahoo/react-intl) library is used for internalization @@ -374,26 +405,6 @@ In order to translate attributes in Angular we should use `i18nFilter`: > ``` -## Node.JS - -`Intl-messageformat` package assumes that the -[Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) -global object exists in the runtime. `Intl` is present in all modern -browsers and Node.js 0.10+. In order to load i18n engine -in Node.js we should simply `import` this module (in Node.js, the -[data](https://github.com/yahoo/intl-messageformat/tree/master/dist/locale-data) -for all 200+ languages is loaded along with the library) and pass the translation -messages into `init` method: - -```js -import { i18n } from '@kbn/i18n'; - -i18n.init(messages); -``` - -After that we are able to use all methods exposed by the i18n engine -(see [I18n engine](#i18n-engine) section above for more details). - ## Build tools In order to simplify localization process, some build tools will be added: