React Component's high order component about internationalization
npm install @rcp/hoc.i18n

React Component's high order component about internationalization
``bash`
npm install @rcp/hoc.i18nor use yarn
yarn add @rcp/hoc.i18n
`javascript
import i18n from '@rcp/hoc.i18n'
const currentLang = 'en-us'
@i18n(
{
'en-us': {
hello: 'hello, ${1}'
},
'zh-cn': {
hello: '你好, ${1}'
}
},
currentLang
)
class View extends React.Component {
render() {
return
{this.i('hello', this.props.title)}
//
// equals to
hello, Jilly
//
// equals to hello from locale, Jilly
//
// equals to 你好, Jilly
`$3
`javascript
import i18n from '@rcp/hoc.i18n'const currentLang = 'en-us'
@i18n(
{
'en-us': {
hello: 'hello, ${1}'
}
},
currentLang
)
class View extends React.Component {
render() {
return
{this.i('hello', this.props.title)}
}
}// Customize view's dictionaries
View.i18n // See https://github.com/imcuttle/tiny-i18n/tree/master/packages/tiny-i18n
View.i18n.setLanguage('zh-cn')
View.i18n.setDictionary(
{
hello: '你好, ${1}'
},
'zh-cn'
)
`$3
`javascript
import i18n from '@rcp/hoc.i18n'@i18n({
hello: 'hello, ${1}',
tip: 'awesome'
})
class View extends React.Component {
render() {
return (
{this.i('hello', this.props.title)}
{this.i('tip')}
)
}
}// Customize dictionary from
props.locale
//
// equals to hello from locale, Jillyawesome
`$3
`javascript
import i18n from '@rcp/hoc.i18n'@i18n({
zh: {
hello: '你好, ${1}',
tip: '酷'
},
en: {
hello: 'hello, ${1}',
tip: 'awesome'
}
})
class View extends React.Component {
render() {
return (
{this.i('hello', this.props.title)}
{this.i('tip')}
)
}
}//
// => '你好 Jilly酷
'
``- tiny-i18n - Tiny yet useful i18n library
This library is written and maintained by imcuttle,
MIT