i18n-node icon indicating copy to clipboard operation
i18n-node copied to clipboard

Cookie parser/something cookies stuff is not working?

Open ipepe opened this issue 9 years ago • 10 comments

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();
    });

ipepe avatar May 25 '15 20:05 ipepe

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

mashpie avatar May 28 '15 12:05 mashpie

Yes i did with that exact example. I will create a repo where i will reproduce a problem.

ipepe avatar May 28 '15 14:05 ipepe

Actually You can see my setup here:

https://github.com/ipepe/dpd-express/blob/master/index.js

ipepe avatar May 28 '15 14:05 ipepe

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

mashpie avatar May 28 '15 15:05 mashpie

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

dynnamitt avatar May 29 '15 08:05 dynnamitt

fixed it! // the order of these lines were REVERSED

app.use(express.cookieParser()); app.use(i18n.init);

dynnamitt avatar May 29 '15 08:05 dynnamitt

@ipepe, how about your setup?

mashpie avatar Jun 02 '15 15:06 mashpie

Im lacking time to check it

ipepe avatar Jun 02 '15 16:06 ipepe

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’.

edimoldovan avatar Oct 15 '15 14:10 edimoldovan

...again: we need more docs & examples (<-- note to myself, any help appreciated)

mashpie avatar Jan 31 '16 20:01 mashpie