This package has been deprecated

Author message:

please use i21n instead

i20n

1.1.2 • Public • Published

i20n

Build Status NPM module Join the chat at https://discord.gg/PBAR2Bz Follow on Twitter

Tiny string internationalization and interpolation library.

Features:

  • Named-variable interpolation
  • Flexible configuration format
  • Set default and fallback locale
  • Works in Node.js and browser
  • Small, no external dependencies

Install

npm install i20n

Usage

const I20n = require('i20n')

const i20n = new I20n({
  /* Basic */
  'hello.world': 'Hello world',
  /* With variables */
  'hello.fullname': 'Hello {name}, your full name is {name} {surname}',
  /* Nested */
  'hello.world.and': {
    'goodbye': {
      'name': 'Hello world, goodbye {name}'
    }
  }
})

// "Hello world"
i20n.t('hello.world')

// "Hello Ram, your full name is Ram Bo"
i20n.t('hello.fullname', {
  name: 'Ram',
  surname: 'Bo'
})

// "Hello world, goodbye Ram"
i20n.t('hello.world.and.goodbye.name', {
  name: 'Ram'
})

Different language translation versions (i.e. locales):

const i20n = new I20n({
  'good': {
    'day': {
      'en-gb': 'Good day {name}',
      'de': 'Guten tag {name}'
    }
  },
  'my': {
    'name.is': {
      'en-gb': 'My name is {name}',
      'zh-TW': '我叫{name}'
    }
  }    
}, {
  /** Locale to use when not explicitly specified or when specified locale version not found */
  defaultLocale: 'en-gb'
})

// Default locale
// "Good day Ram"
i20n.t('good.day', {
  name: 'Ram'
})

// Override with a specific locale
// "Guten tag Ram"
i20n.t('good.day', {
  name: 'Ram'
}, {
  locale: 'de'
})

// Override with a specific locale for which there is no string - it uses the default locale instead!
// "My name is Ram"
i20n.t('my.name.is', {
  name: 'Ram',
  locale: 'de'
})

License

MIT - see LICENSE.md

Package Sidebar

Install

npm i i20n

Weekly Downloads

2

Version

1.1.2

License

MIT

Last publish

Collaborators

  • hiddentao