Skip to content

Translate with pluralization and variables in under 600b.

License

Notifications You must be signed in to change notification settings

ajoslin/nanotranslate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Translate with pluralization and variables in under 600b.

Resources

License

Stars

Watchers

Forks

Packages

No packages published