jeresig/i18n-node-2

setLocaleFromQuery() isn't working

Closed this issue · 1 comments

Hi,

I've added following middle ware to set locale in each request using query (?lang=fi):

var express = require('express'),
i18n = require('i18n-2');

i18n.expressBind(app,
    {
        locales:['en', 'fi', 'nb', 'es'],
        defaultLocale: 'en',
        cookieName: 'locale'
    });


app.use(function(req, res, next) {
    req.i18n.setLocaleFromQuery();
    next();
});

Then whenever I'm trying console.log(req.i18n.__("Hello")) then its always giving translation of "Hello" in en locale(English) although I'm using other locale in the query like the following
myApi.com/getUserInfo?lang=fi

The locale is always set to en!!!

What am I missing?
Thanks in advance

I believe you need to pass the req object into the method:

req.i18n.setLocaleFromQuery(req);