babel-plugin-react-intl

React-intl define messages outside of react

一笑奈何 提交于 2020-01-14 07:41:43
问题 I have utils.js file. export function categoryIdToCategoryName(categoryId) { let name; switch (categoryId) { case constants.RISK_CATEGORY_LOW: name = 'low'; break; case constants.RISK_CATEGORY_MEDIUM: name = 'medium'; break; case constants.RISK_CATEGORY_HIGH: name = 'high'; break; case constants.RISK_CATEGORY_CRITICAL: name = 'critical'; break; default: console.warn('see: /utils/risk.js', 'categoryIdToCategoryName:', categoryId); name = 'unknown'; } return name; } I would like to translate

Dynamically import language json file for react / react-intl

核能气质少年 提交于 2019-12-21 13:08:10
问题 This is the way I configure my client to render the proper language through react-intl. import localeData from './translations/en.json'; //import localeData from './translations/xx.json'; <-- any language const render = routes => { match({ history, routes }, (error, redirectLocation, renderProps) => { ReactDOM.render( <HotEnabler> <IntlProvider locale={locale} messages={localeData}> <Provider store={store} app={app} restApp={restApp} key="provider"> <Router {...renderProps} render=

How to add locale data dynamically using React Intl?

荒凉一梦 提交于 2019-12-11 00:29:52
问题 Am using React-intl for internationalization of an UI Util Library. The library has a folder say i18n wherein I place json files for different locales.If the user of this library want to add support for additional locales, he/she can place additional json file with key/value pairs for the respective locale. But React-intl requires to import and addLocaleData for the respective locale in prior.For example, import fr from 'react-intl/locale-data/fr'; addLocaleData([...fr]); Is there a way to