u18next节点setLng似乎不起作用 [英] u18next node setLng seems that doesn´t work

查看:88
本文介绍了u18next节点setLng似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了用于node.js的模块i18next的问题(使用express).我以这种方式(在app.js文件上)初始化模块:

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');
    });
});

第一个console.log有效,但第二个则无效...我在做什么错?有帮助吗?

The first console.log works, but not the second... What am I doing wrong?? Any help??

谢谢.

推荐答案

我找到的解决方案

最后,我看到i18n.setLng函数没有使用回调...我唯一需要做的是:

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');

感谢@Alexandr

Thanks @Alexandr

这篇关于u18next节点setLng似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆