x18n.js is an internationalisation library for JavaScript and react-x18n is a helper library which takes care of updating the user interface for you.
How to use it
Just require the module whenever you need internationalisation:
let x18n t =
As you can see the react-x18n
module exports two objects: x18n
and t
:
Use the x18n
property to access the API provided by x18n.js (registering dictionaries, changing language, etc.).
But instead of using the t
function provided by x18n.js, use the t
function provided by react-x18n
to create self-updating elements.
To learn about the x18n.js API, head over to the repository.
How does it work?
t('key')
and t.plural('key')
both will return a new react element that will take care of updating itself dynamically.
This means you don't need to worry about updating the UI when the language changes.
Example
let React = let ReactDOM = let x18n t = // Dictionary for english languagex18n // Dictionary for german languagex18n // Create react elementlet App = React // Render the appReactDOM
Installation and tests
npm install react-x18n --save
This will automatically install the x18n.js library for you as well.
To run tests (standard.js compliance check and jest unit tests):
npm test
Roadmap
- Misc:
- Better unit-tests.