Reduxtionalization (Redux I18N)
A Redux Internationalization with bindings.
1. About
R16N is a simple easy-to-use redux (reducer, action, and state selectors) for your
translations, and localized dates and number, which you are going to use throughout
your app.
R16N also has bindings for React.
There will be new bindings for different Front-End JS frameworks.
2. Installation
Using npm:
npm install r16n
Using yarn:
yarn add r16n
3. Usage
3.1. Creating R16N reducer
Create R16N reducer with your own locales, and the current locale.
R16N's reducer name has to be
r16n
, otherwise it won't work.
3.2. Working with your translations
3.2.1. Get a translation:
To get a translation state from redux, call getTranslation(state, key)
args :
state
: Redux store state.key
: dot-separated string indicating your translation path.
If your locales object was the following:
dummyKey
, and nestedKey.anotherKey
are valid translation keys.
example :
The same works on every locale you provide.
3.2.2. Get current translations state:
To get the entire current translations state in case you needed it, call getTranslations(state)
.
args :
state
: Redux store state.
example :
3.2.3. Get current locale state:
To get the current locale state of the app, call getLocale(state)
.
args :
state
: Redux store state
example :
3.3. Change your app's locale
setLocale(locale)
:
Sets the locale code you've passed and its translations as the current translations and locale of your app.
example :
4. Bindings
4.1. React
The following are React Components that are already connected to with R16N.
Whenever
setLocale(...)
action is called with new locale, they re-render with the localized value.
4.1.1. Translation
A binding for getTranslation(state, key)
Props :
tKey
: it is like thekey
attribute forgetTranslation(...)
example:
4.1.2. Date
A binding for localizing dates, it uses Moment.js
for formatting and translating dates.
Whenever setLocale(...)
action is called with new locale, it re-renders with the localized date.
Props :
value
: Date value whether it is (epochnumber
,string
, orDate
object).format
: formatstring
, or a locale-format mapping object. check Moment.js Displaying reference.
example :
4.1.3. Number
A binding for localizing numbers.
Props :
value
: thenumber
or numberstring
you want to localize.
example :
React Example
5. License
The MIT License (MIT) Copyright (c) 2018 Radwan Abu Odeh radwanizzat[at]gmail.com