Node i18n
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.editorconfig
.eslintrc
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

i18n

Build Status codecov

Node i18n

Install

$ npm i @acyort/i18n -S

Usage

const i18n = new I18n(dir, [locale])  // initial
i18n.locale = 'en'  // set locale
const locale = i18n.locale  // get current locale
# language
three: Hello %s
num:
  zero: not cats
  one: only one cats
  other: is %d cats
a:
  b:
    c: s%2$s a %1$s
const I18n = require('@acyort/i18n')
const { join } = require('path')

let i18n = new I18n(join(__dirname, 'locales'))

i18n.locale = 'default'

i18n.__('three', 'aaaa')  // 'Hello aaaa'
i18n.__('a.b.c', 'aaaa', 'bbbb')  // 'sbbbb a aaaa'
i18n._n('num', 0) // 'not cats'
i18n._n('num', 1) // 'only one cats'
i18n._n('num', 1000)  // 'is 1000 cats'

i18n = new I18n(join(__dirname, 'locales'), 'default')

console.log(i18n.locale)  // 'default'
i18n._n('num', 1000)  // 'is 1000 cats'