Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferred language is not saved in the cookie #57

Open
kleinpetr opened this issue Oct 24, 2024 · 7 comments
Open

Preferred language is not saved in the cookie #57

kleinpetr opened this issue Oct 24, 2024 · 7 comments

Comments

@kleinpetr
Copy link

I would like to know what should be the expected behavior of the cookie user-locale

My Expectation
// having en-US browser

  1. visit the web which resolves en locale - detected by browser
  2. switch locale to cs or any other lang - now the cookie should change to cs value
  3. close website
  4. visit website -> now I would expect the web will be in cs locale

This is how standard i18n works imo.

Thanks for clarification

@s00d
Copy link
Owner

s00d commented Oct 24, 2024

On the first visit to the website, the locale is determined and the user is redirected to the page corresponding to the detected locale. On subsequent visits, the user is taken to the same link they accessed, meaning the locale determination does not occur again. As far as I remember, i18n works similarly.

@kleinpetr
Copy link
Author

you can try it in the demo, ideally in the anonymous window, https://stackblitz.com/github/kleinpetr/nuxt-content-i18n_micro

  1. visit the page (it should be redirected to /en prefix
  2. open another tab, access the website again, it is not redirected to /en and stays with the default cs lang even though I didn't change the locale in the first session
  3. in the second session change the locale to /en
  4. open another tab and it will resolves again in just cs

@s00d
Copy link
Owner

s00d commented Oct 24, 2024

You haven't enabled the autoDetectLanguage option, but after enabling redirects, it started working. The only thing I want to clarify is that I’m using a 301 redirect, and because of this, the browser remembers the redirect and performs it automatically when reopening the page. I could try switching to a 302, which should theoretically solve the issue.

@kleinpetr
Copy link
Author

we have already set autoDetectLanguage in another project, so I've updated it in the demo as well, but I am trying to debug the cookie itself and when I change the language using switcher, the cookie is not changed anymore, that would be the issue imo.

@s00d
Copy link
Owner

s00d commented Oct 24, 2024

try v1.30.1

I changed the redirect to 302. For re-detecting the locale, additional logic needs to be added, but I haven't done it yet. I'll look into it when I have time. Currently, it works as follows:

  1. On the first visit, it detects the locale, redirects, and saves it in cookies.
  2. On subsequent visits, it doesn't use the redirect logic.

If you have time, you can try implementing the logic for re-redirecting yourself. You'll just need to add an option to enable this feature. I'll try to find time for it later.

@kleinpetr
Copy link
Author

So it means, when user switch the locale, it is not saved in the cookie, right? so there is nothing like "preferred language" which would be kept for another visit.

@kleinpetr kleinpetr changed the title Preffered language from cookie is not set by default Preferred language from cookie is not set by default Oct 24, 2024
@kleinpetr kleinpetr changed the title Preferred language from cookie is not set by default Preferred language is not save in the cookie Oct 24, 2024
@kleinpetr kleinpetr changed the title Preferred language is not save in the cookie Preferred language is not saved in the cookie Oct 24, 2024
@s00d
Copy link
Owner

s00d commented Oct 24, 2024

So it means, when user switch the locale, it is not saved in the cookie, right? so there is nothing like "preferred language" which would be kept for another visit.

yes that's true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants