2.2.1 • Published 4 years ago
anytv-i18n v2.2.1
anytv-i18n
A module for app internationalization
Install
npm install anytv-i18n@latest --saveIntroduction
Simple example:
'use strict';
const i18n = require('anytv-18n');
i18n.configure({
languages_url: 'http://translations.myapp.com/:project/languages',
translations_url: 'http://translations.myapp.com/:project/:lang.json',
locale_dir: path.resolve('translations'),
default: 'en',
debug: true
});
i18n.use('freedom_dashboard')
.load()
.then(() => {
// function to call when everything is loaded
i18n.trans('zh_TW', 'greetings', {
name: 'Raven!'
});
i18n.trans('non_existent_key'); // empty string
})
.catch(() => {
// function to call when there's an error
});Configuration options
languages_urlurl for getting all available languages in json.:projectwill be replaced by the project you're using. Exact JSON format:
{
"data": {
"languages": [
"en",
"zh",
"zh_TW"
]
}
}translation_urlurl for getting json translations.:projectwill be replaced by the project you're using.:langwill be replaced by the language you're using. Exact format:
{
"greetings": "你好 :name",
...
}locale_dirdirectory where the translations will be cached. should be an absolute path with a trailing backslach. example:/home/user/my-app/translations/debugset to true if you want to debugloggerreplaces the default loggernote: Only Winston-like loggers are accepted
Todo
- Add test cases
Contributing
Install the tools needed:
npm install grunt -g
npm install --devTo compile the ES6 source code to ES5:
gruntTo generate the docs:
esdoc -c ./esdoc.jsonRunning test
npm testCode coverage
npm run coverageThen open coverage/lcov-report/index.html.
License
MIT