I am using mashpie i18n localization package in my nodeJS application. Here is the github link of the same package.
Here is my app.js code:-
i18n.configure({
locales : ['en','ar'],
defaultLocale : 'en',
autoReload : true,
directory : __dirname + '/lang',
synFiles : true,
fallbackLng : "en",
});
.....................
.....................
app.use(i18n.init);
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
var apiLocale = (req.headers['accept-language']).toLowerCase(); console.log('accept language', apiLocale);
i18n.setLocale(apiLocale || 'en');
console.log('Get after set locale', i18n.getLocale()); // displays en as locale
next();
});
This is the header data I am sending:-
Access-Control-Allow-Origin:*
Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept
accept-language:ar
This code is acting strangely. If I try to display accept-language
value via console.log, I see 'ar'
is getting displayed. However, this particular line
console.log('Get after set locale', i18n.getLocale());
displays 'en'
as locale. That means somehow 'ar'
is not getting set as locale, but 'en'
is getting set. However if I make the following changes-
i18n.configure({
locales : ['en','arabic'],
...............
...............
});
and then send accept-language
value as 'arabic'
instead of 'ar'
, the line of code
console.log('Get after set locale', i18n.getLocale());
displays 'arabic'
as locale.
Seems like 'ar'
has some issue with i18n. How to fix this?