i18n-node
i18n-node copied to clipboard
Cookie parser/something cookies stuff is not working?
I had to write my own middleware for setting language in cookie, is there something not working properly or is it my express?
app.use(function (req, res, next) {
if( req.headers.cookie && req.headers.cookie.indexOf && req.headers.cookie.indexOf('lang=') > -1){
var cookie = req.headers.cookie;
req.setLocale(cookie[cookie.indexOf('lang=')+5]+cookie[cookie.indexOf('lang=')+6]);
}
next();
});
as far as I know (and use cookieparser in my projects) there are no issues. Did you setup cookieparser middleware?
- express4 example: https://gist.github.com/mashpie/08e5a0ee764f7b6b1355
- express3 example: https://gist.github.com/mashpie/5124626
Yes i did with that exact example. I will create a repo where i will reproduce a problem.
Actually You can see my setup here:
https://github.com/ipepe/dpd-express/blob/master/index.js
looks correct... well, comparing https://github.com/mashpie/i18n-node/blob/master/i18n.js#L381 with your middleware keeps me thinking of a buggy cookieParser implementation in your setup. But this is just a quick guess
Same issue I have used the express+hbs+cookie setup sample... but still "accept-language" header is 1st priority
to be fair.. i never managed w i18n-2 either
fixed it! // the order of these lines were REVERSED
app.use(express.cookieParser()); app.use(i18n.init);
@ipepe, how about your setup?
Im lacking time to check it
I have a similar issue, but with hapi. I am unable to make i18n actually use the language set in the cookie. This is the hapi plugin I am using: https://github.com/codeva/hapi-i18n Cookie says ‘en’ i18n returns value for ‘de’.
...again: we need more docs & examples (<-- note to myself, any help appreciated)