I\'m building an app that will need to be available in multiple languages and locales.
My question is not purely technical, but rather about the architecture, and th
Antoine's solution works fine, but have some caveats :
That's why we built redux-polyglot on top of both Redux and AirBNB's Polyglot.
(I'm one of the authors)
setLanguage(lang, messages) getP(state) selector that retrieves a P object that exposes 4 methods :
t(key): original polyglot T functiontc(key): capitalized translationtu(key): upper-cased translationtm(morphism)(key): custom morphed translationgetLocale(state)selector to get current languagetranslate higher order component to enhance your React components by injecting the p object in propsimport setLanguage from 'redux-polyglot/setLanguage';
store.dispatch(setLanguage('en', {
common: { hello_world: 'Hello world' } } }
}));
import React, { PropTypes } from 'react';
import translate from 'redux-polyglot/translate';
const MyComponent = props => (
{props.p.t('common.hello_world')}
);
MyComponent.propTypes = {
p: PropTypes.shape({t: PropTypes.func.isRequired}).isRequired,
}
export default translate(MyComponent);
Please tell me if you have any question/suggestion !