Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 1.02 KB

readme.md

File metadata and controls

42 lines (32 loc) · 1.02 KB

nanotranslate Build Status

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