Translate function with templates precompiling and helpers
npm install --save translate-text
import createTranslate from 'translate-text'
import pluralize from 'numd'
const translation = {
hello: 'Hello',
echo: 'You say: $1',
more: {
age: 'I\'m a (pluralize $1|year|years) old'
},
greeting: 'I\m $name and I\'m (pluralize $age|year|years) old'
}
const translate = createTranslate(translation, {pluralize})
translate('hello') // Hello
translate('echo', 'Foo') // You say: Foo
translate('more.age', 25) // I'm a 25 years old
translate('greeting', {
name: 'John Smith',
age: 25
}) // I'm John Smith and I'm 25 years old
Compile templates and return translate function.
Type: object
Translation templates.
Type: object
Helper functions that are used in templates.
Type: string
Template key.
Type: ...any
Arguments to insert into the template.
- react-translate-text — React higher-order component for text translation
MIT