Translations doesn't work when switching language with disabled useCookie property

thnima
0
thnima
commented 3 months ago

Version

v6.4.1

Reproduction link

https://codesandbox.io/s/thirsty-lake-m7vwr

Steps to reproduce

Click on the link with the label: "Deutsch"

What is expected ?

The string "English string" should get translated to "Deutscher string"

What is actually happening?

Clicking the link changes the route to "/de", which is fine. But the text doesn't get translated.
If you set useCookie: true in the nuxtConfig again, it works as expected.
Same behaviour can be observed, when you set useCookie: true AND disable the cookies in the browser

bug
0
rchl
1.1k
rchl
commented 3 months ago

Looks like a bug, the module logic should be improved.

For your case, you could set detectBrowserLanguage to false. Currently you have it set to:

detectBrowserLanguage: {
  useCookie: false,
  alwaysRedirect: false,
  cookieKey: "i18n_redirected",
  fallbackLocale: "en"
}
0
thnima
0
thnima
commented 3 months ago

True, setting detectBrowserLanguage: false works indeed.
Maybe I should have mentioned the actual use case:
The problem here is: I want to use the cookie, if cookies are enabled. But on environments where cookies are disabled, it doesn't work.
So assume setting useCookie: true and disable your cookies in the browser. Then the behavior is the same, as when you set useCookie: false

I will add this to the description

0
gokhancetiner
0
gokhancetiner
commented 2 months ago

Hello @rchl,

Do you have a deadline to fix this bug?

Many Thanks,

0
rchl
1.1k
rchl
commented a month ago

I'm trying to think of what would be the expected flow in that case…

  • Since detectBrowserLanguage is set we try to detect browser language and redirect to a matching route.
  • Since cookie is not set (or useCookie is false) we always behave like it's initial navigation and trigger redirect.

It's not that obvious how this should be fixed…
While there is a hacky way to test on the client if cookies are enabled and maybe act differently in that case, there is no way to do that on the server. So I could change the code so that client-side navigations are not affected by this problem but once you reload the page (or even navigate in non-SPA fashion), it will still redirect to the fallback locale. So it would only be half-fixed.

I wonder if anyone has some solid ideas that I might be overlooking?

0
rchl
1.1k
rchl
commented a month ago

Also, the useCookie option is documented with Set to false to redirect every time so it's really doing what it's supposed to (for the useCookie=false case at least). If we assume that, the only issue I see is that it is possible to end up in this broken state where locale in the URL changes but not the actual locale.

For the case when cookies are disabled, one could argue it's a plain bug but it's not easy or even possible to distinguish those cases.

0
gokhancetiner
0
gokhancetiner
commented a month ago

obvious

Hello @rchl ,

You are right we can use useCookie is false and it works for redirection but the problem is if we set useCookie is false and if we change the lang, the URL changes but translations don't work.

If we set useCookie is true I have another problem explained below link

https://cmty.app/nuxt/nuxt-i18n/issues/c397

Many Thanks

0
rchl
1.1k
rchl
commented a month ago

Yes, but as I've explained, that's pretty much what such configuration is supposed to do - always follow browser language and not allow changes to the locale.

Your other issue with setCookie = true looks like #491.

0
gokhancetiner
0
gokhancetiner
commented a month ago

Yes, but as I've explained, that's pretty much what such configuration is supposed to do - always follow browser language and not allow changes to the locale.

Your other issue with setCookie = true looks like #491.

My problem is if browserLang and cookie lang are different redirections don't work.
On #491 you set default lang but I want to redirect user's default browser lang

0
Informations
Bug ReportOpen
#c370 - Created 3 months ago