react-fluxible-i18n
Simple i18n translation and localization components and helpers for React+Fluxible applications.
Note: If you are not using Fluxible, you can use react-i18nify instead. If you are using Redux, you can use react-redux-i18n instead.
Preparation
First install the package:
npm i react-fluxible-i18n --save
Secondly, register the I18nStore
in your app:
var Fluxible = ;var I18nStore = I18nStore; const app = // ...; app;
Finally, set the translations and locales to be used, by dispatching events:
context; context;
Now you're all set up to start unleashing the power of react-fluxible-i18n
!
Components
The easiest way to translate or localize in your React components is by using the Translate
and Localize
components:
var React = ;var Translate = Translate;var Localize = Localize; var AwesomeComponent = React;
Helpers
If for some reason, you cannot use the components, you can use the I18n.t
and I18n.l
helpers instead:
var I18n = I18n; I18n; // => returns 'Toffe app met i18n!' for locale 'nl'I18n; // => returns 'Hallo, Aad!' for locale 'nl'I18n; // => returns 'Niks te exporteren' for locale 'nl'I18n; // => returns 'Weird key' as translation is missingI18n; // => returns {hello: "Hallo, Aad!", title: "Toffe app met i18n!"} for locale 'nl' I18n; // => returns '1 december 2013' for locale 'nl'I18n; // => returns '3,14' for locale 'nl'
Supported localize options
The localize component and helper support all date formatting options as provided by the Javascript moment
library. For the full list of options, see http://momentjs.com/docs/#/displaying/format/.
For number formatting, the localize component and helper support all options as provided by the Javascript built-in Intl.NumberFormat
object. For the full list of options, see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat.