nanotranslate
v2.0.0
Published
Translate with pluralization and variables in under 600b.
Downloads
7
Maintainers
Readme
nanotranslate
Translate with pluralization and variables in under 600b.
Install
$ npm install --save nanotranslate
Usage
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'
License
MIT © Andrew Joslin