收录了这篇文章
安装
npm install i18n --save
i18n.js
var i18n = require('i18n');
i18n.configure({
locales: ['en-US', 'zh-CN'], // setup some locales - other locales default to en_US silently
// defaultLocale: 'zh-CN',
defaultLocale: 'en-US',
directory: __dirname + '/locales',
updateFiles: false,
indent: "\t",
extension: '.json'
});
module.exports = function (app) {
// default: using 'accept-language' header to guess language settings
app.use(i18n.init);
};
zh-CN.js
{
"Hello":"你好,世界!"
}
en-US.js
{
"Hello":"Hello, world!"
}
app.js
[...]
require('./i18n.js')(app);
[...]
test.controller.js
console.log("test...", i18n.__('Hello'));
参考:
https://www.npmjs.com/package/i18n
https://github.com/mashpie/i18n-node
声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。