I18n-module: Issue with the redirect cookie

Created on 12 Apr 2018  路  4Comments  路  Source: nuxt-community/i18n-module

Version

2.6.1

Reproduction link

https://github.com/nuxt-community/nuxt-i18n

Steps to reproduce

Using Nuxt 1.4.0 and Nuxt i18n 2.6.1, add the following config for the module:

locales: [
        {
          code: 'de',
          iso: 'de-DE',
          name: 'German'
        },
        {
          code: 'en',
          iso: 'en-US',
          name: 'English'
        }
      ],
      defaultLocale: 'de',
      detectBrowserLanguage: true,
      useRedirectCookie: false,
      vueI18n: {
        fallbackLocale: 'de',
        messages: {
          'de': require('./locales/de.json'),
          'en': require('./locales/en.json')
        }
      }

What is expected ?

If I change the language on my application from english to german the language has to be the same (the last selected) even if I refresh the page.

If I change the language on my application from english to german and then I refresh the page the language should be german.

What is actually happening?

If I change the language on my application from english to german and then I refresh the page, the module redirects me to the english version automatically instead of keeping the german version.

Additional comments?

I think the reason is because this line of code is true practically every time:

https://github.com/nuxt-community/nuxt-i18n/blob/7cc8eafd501eb5490b79259c6940115cc105e477/lib/templates/i18n.routing.middleware.js#L26

If I change that line to this it works well:

if (typeof req.headers['accept-language'] !== 'undefined' && useRedirectCookie) {

Any thoughts?

Thanks in advance! 馃憡馃徏

This bug report is available on Nuxt.js community (#c64)

Most helpful comment

Awesome! Thank you so much @paulgv! 馃槃

I've already tested it and is working as expected 馃憤

All 4 comments

Hi @eddiesigner
The useRedirectCookie option is actually meant to prevent those excessive redirections, is there any reason your disabled it? I'd recommend you set it to true :)

Oh, I forgot to say, I had that value before but it was the same 馃槥 for that reason I think that line is true every time, it doesn't matter if you put false or true on the useRedirectCookie option.

At least in my application the line numer 40 is always reached :/

https://github.com/nuxt-community/nuxt-i18n/blob/develop/lib/templates/i18n.routing.middleware.js#L40

Hey @eddiesigner
Sorry for the delay. I looked into the issue and it does look like there were some pretty inconvenient bugs in the middleware 馃槗
I pushed a fix in v2.9.4 which should solve your issue, I hope you can give it a try and give me some updates :)

Awesome! Thank you so much @paulgv! 馃槃

I've already tested it and is working as expected 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Josepdal picture Josepdal  路  17Comments

koteezy picture koteezy  路  16Comments

simplenotezy picture simplenotezy  路  28Comments

alexgrozav picture alexgrozav  路  21Comments

lucassith picture lucassith  路  28Comments