Closed nazmul-prince closed 5 years ago
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
console.log(req.i18n.__("Hello"))
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
req.i18n.setLocaleFromQuery(req);
Hi,
I've added following middle ware to set locale in each request using query (?lang=fi):
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=fiThe locale is always set to en!!!
What am I missing? Thanks in advance