i18n-helper
I18n helper for node, you can use it as a helper in jsx , handlebars , ejs or any other template engines .
Install
npm install i18n-helper --save
Usage
var locale = 'en';var langs = en: 'greetings': 'Hello {1} !' zh: 'greetings': '你好 {1}!' ; var i18n = langslocale; console; // => 'Hello Jack !'
Init
i18n-helper
exports a generator which returns an i18n helper.
You can pass multiply resources into this generator, the resources will be merged to one from right to left.
// global resource and module resourcevar globalLangs = ;var moduleLangs = ; // the i18n helper generatorvar i18nHelperGenerator = ; // create an i18n helper with the giving resourcesvar i18nHelper = ;
Find Key
The helper will try to find the matched key from the merged resource, if not found, the key itself is returned.
var i18n = ; console;// => 'key'
You can override i18n.keyNotFound
to apply your customized key not found
handler ( >= 1.1.0 ).
var i18n = ; i18n { return key + ' is not found';}; console;// => 'key is not found'
Template
If the value to the key is a template ( with a string like {1}
),
then the arguments will be substituted into the template.
var i18n = ; console;// => 'Hello Jack ! Welcome to China .'
Change Log
1.2.0
- support templating key #1.
1.1.0
- add
keyNotFound
handler.