kantan-i18n
Really simple internationalization system.
Check the API documentation here.
Install
npm install --save kantan-i18n
or
yarn add kantan-i18n
Usage
const I18n = ; // English translations for your texts// You probably want to load this from a different fileconst definitionsEN = simple: 'This is a simple text' `This text accept parameters (foo: and bar: )` 'items.none': 'No items.' `1 item ().` ` items ().`; // Spanish translations for your texts// You probably want to load this from a different file, only when requiredconst definitionsES = simple: 'Esto es un texto sencillo' `Este texto acepta parámetros (foo: y bar: )` 'items.none': 'Ningún artículo.' `1 artículo ().` ` artículos ().`; // Japanese translations for your texts// You probably want to load this from a different file, only when requiredconst definitionsJA = simple: 'これは簡単な文言です' `この分で、パラーメタを使うことができます (foo: と bar: )` 'items.none': '商品なし.' `商品一つ ().` `商品つ ().`; // This is your quantity map. It should be shared between all your translationsconst qtyMap = items: 0: 'items.none' // items.none will be used when calling items with n = 0 1: 'items.one' // items.one will be used when calling items with n = 1 _: 'items.lots' // items.lots will be used when calling items with any other value // i18n object is initialized here with EN and ES translationsconst i18n = 'en' en: definitionsEN es: definitionsES qtyMap; // let's get simple text in English:const text = i18n;// text = 'This is a simple text' // let's get complex text in Spanish:i18n;const complex = i18n;// complex = 'Este texto acepta parámetros (foo: 123 y bar: abc)' // let's load Japanese translations and get a quantity dependant onei18n;i18n;const qty = i18n;// qty = '商品3つ (*#^#*).'
You can also define an alias to avoid writing i18n.translate
all the time:
const _ = i18ntranslate;const _n = i18ntranslateN; i18n;; // This is a simple text; // No items.