【发布时间】:2019-04-03 19:08:47
【问题描述】:
我试图瞄准,这样我就可以在被调用的函数中使用 i18n。
我有错误:
(node:15696) UnhandledPromiseRejectionWarning: TypeError: i18n.__ is not a function
我怎样才能让 i18n 可以在函数内部工作而不必在请求中?
Server.js:
var i18n = require('i18n-2');
global.i18n = i18n;
i18n.expressBind(app, {
// setup some locales - other locales default to en silently
locales: ['en', 'no'],
// change the cookie name from 'lang' to 'locale'
cookieName: 'locale'
});
app.use(function(req, res, next) {
req.i18n.setLocaleFromCookie();
next();
});
//CALL another file with some something here.
其他文件.js:
somefunction() {
message = i18n.__("no_user_to_select") + "???";
}
我应该如何解决这个问题?
【问题讨论】:
标签: javascript node.js internationalization global