Basic implemetation of multilang support for NodeJS.
npm install basic-multilang --save
var I18n = require('basic-multilang');
Create a instance to render I18n.
Name | Type | Description |
---|---|---|
directory |
string |
Translations directory. |
reload |
function |
Funcion to load files. If !reload then will be used require . |
// Option 1
var i18n = new I18n(path.resolve(__dirname, 'i18n'));
// Option 2
var reload = require('require-reload')(require);
var i18n = new I18n(path.resolve(__dirname, 'i18n'), reload);
Set language to use.
Name | Type | Description |
---|---|---|
lang |
string |
Language to set. This will be key to get el translation. |
i18n.setLang('es');
Return then language to seted.
const lang = i18n.getLang();
Return the translation for a specific key.
Name | Type | Description |
---|---|---|
key |
string |
Key to get translation. |
var i18n = new I18n(path.resolve(__dirname, 'i18n'));
i18n.setLang('es');
const translation = i18n.get('mysubdirectory.myfile.myphrasekey');
// in file ./i18n/mysubdirectory/myfile.js[on], get poperty myphrasekey.es.
If you have any kind of trouble with it, just let me now by raising an issue on the GitHub issue tracker here:
https://github.com/arondn2/basic-multilang/issues
Also, you can report the orthographic errors in the READMEs files or comments. Sorry for that, English is not my main language.
npm test
or npm run cover