Frontend internationalization component base React
npm : npm install rc-i18n
yarn : yarn add rc-i18n
First, base on your language requirement to config i18n.json
file, just like:
{
"zh-CN": {
"say_hi": "ä½ å¥½!"
},
"en-US": {
"say_hi": "Hi!"
}
}
In your code, import & usage:
import I18n, { injectAsyncI18n } from './rc-i18n';
// you need to inject i18n.json frist
injectAsyncI18n('TEST', require('./i18n'));
render() {
<I18n region={'TEST'} i18n="say_hi" />
}
-
getCurrentLanguage:
(): CN-zh | en-US
get current language in window locale -
switchLanguage:
(language: CN-zh | en-US): void
switch language withCN-zh | en-US
-
get:
(region: string, i18n: string, params: {[name]: string }) : string
get local language value