问题
I am getting a problem with the module i18next for node.js (using express). I initialize (on the app.js file) the module in this way:
i18n.init({
ns: { namespaces: ['text'], defaultNs: 'text'},
resSetPath: 'locales/__lng__/new.__ns__.json',
preload: ['es', 'uk', 'fr', 'ge', 'ru', 'it'],
saveMissing: true,
debug: true,
lng:"es",
sendMissingTo: 'fallback',
useCookie: false,
detectLngFromHeaders: false,
detectLngFromPath: false
});
and on the routes files I make something like this:
router.get('/not_registered', function(req, res) {
console.log("users.js-> user.get-> init lang: " + req.session.lang);
req.i18n.setLng(req.session.lang, function(t)
{
console.log("users.js-> user.get-> inside function");
res.render('users/user');
});
});
The first console.log works, but not the second... What am I doing wrong?? Any help??
Thank you.
回答1:
SOLUTION I FOUND
Finally, I saw that the i18n.setLng function doesn´t use a callback... the only I needed to do was:
req.i18n.setLng(req.session.lang);
res.render('users/user');
Thanks @Alexandr
来源:https://stackoverflow.com/questions/29098492/u18next-node-setlng-seems-that-doesn%c2%b4t-work