open-i18n
用来处理多语言问题,是一个中间件类型的插件, 主要处理错误信息里的语言问题
Quick start
npm install open-i18n --save
Usage
var i18n = require('i18n');
// languages System allow language
// locale Current request use lanuage
// language packages,
/*
{
"zh": {
"hello world": "你好世界。"
},
"en": {
"hello world": "Hello world."
}
}
*/
var t = i18n(languages, locale, LANGS).t;
t('hello world'); // return "你好世界"
// middle-ware auto handle res.body when request error
server.use(i18n.middleWare(languages, defaultLanguage, LANGS))
Collect language items
find ./src/app -type f | node_modules/.bin/open-i18n read > bin/locale/application.pot msgmerge -UN --no-wrap ./bin/locale/en.po ./bin/locale/application.pot msgmerge -UN --no-wrap ./bin/locale/zh.po ./bin/locale/application.pot
Translate language items
Edit en.po
, zh.po
to translate.
Make language package
node_modules/.bin/open-i18n write ./bin/locale/zh.po zh > locale/zh.json