@acyort/i18n

Node i18n

Usage no npm install needed!

<script type="module">
  import acyortI18n from 'https://cdn.skypack.dev/@acyort/i18n';
</script>

README

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'