Translate with pluralization and variables in under 600b.
$ npm install --save nanotranslate
var Translate = require('nanotranslate')
var translate = Translate({
id: 'en_US',
values: {
SIMPLE: 'simple string',
TEMPLATED: 'simple {{value}} string',
PLURAL: [
'Zero items left.',
'One item left.',
'{{count}} items left, {{name}}.'
],
FN: ({ value }) => 'Hello, ' + value
}
})
translate.id // => 'en_US'
translate('SIMPLE') // => 'simple string'
translate('TEMPLATED', {value: 'hello'}) // => 'simple hello string'
translate('PLURAL', {count: 1}) // => 'Zero items left.'
translate('PLURAL', {count: 2}) // => 'One item left.'
translate('PLURAL', {count: 3, name: 'Alex'}) // => '3 items left, Alex.'
translate('FN', { value: 'world'}) // => 'Hello, world'
MIT © Andrew Joslin