u18next node setLng seems that doesn´t work

℡╲_俬逩灬. 提交于 2020-01-17 02:19:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!