u18next node setLng seems that doesn´t work

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.

Upvotes: 0

Views: 120

Answers (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

Upvotes: 1

Related Questions