Closed Fiyuva closed 6 months ago
Would you be able to provide a reproduction? 🙏
I tried to reproduce it but failed, so I showed it as a picture.
When the user sets the cookie value to a random value as in the picture and refreshes the page, it does not return to the default value.
If the cookie value is en or tr, the system works perfectly.
The part I don't understand here is why the default doesn't work when the user manually changes the cookie value.
Based on your description it doesn't sound like a bug, of course editing cookies by hand to unexpected values will result in undefined behaviour.
That said, I can see this happen in an edge case which could happen when a website removes a language which previously would have been saved in a cookie. In such cases it would make sense to redirect/fallback to the default language.
I tried to reproduce it but failed, so I showed it as a picture.
Did you try making it using stackblitz? You may need to open the preview in a new tab for the cookies to work. Even if I understood the issue correctly a reproduction would be useful for me to test a solution on (and add tests for it).
I think I did.
https://stackblitz.com/edit/github-kvjw8r-jgxyrr?file=nuxt.config.ts
When the cookie value is changed manually, it does not return to the default value. How can I solve this problem?
any update?
Unfortunately I was busy with other issues and my day job, will look into this when I have the time.
With #2841 merged the locale cookie should revert to the defaultLocale
if configured (or undefined
if not) if the locale cookie does not match any configured locales.
You can try it out on the edge channel (npm i -D @nuxtjs/i18n@npm:@nuxtjs/i18n
npm i -D @nuxtjs/i18n@npm:@nuxtjs/i18n-edge
), let me know if you run into any issues!
I did the following steps.
1- npm i -D @nuxtjs/i18n@npm:@nuxtjs/i18n
2- I changed the cookie value to an irrelevant value and refreshed the page. I got the results in the picture above.
I checked what you wrote, but I couldn't correct the mistake. DefaultLocale doesn't seem to be working or I couldn't do it.
Oh I'm sorry, I made a mistake in the install command 😥 it should be npm i -D @nuxtjs/i18n@npm:@nuxtjs/i18n-edge
.
My problem is solved. Thanks
Environment
Reproduction
i18n: { baseUrl: process.env.BASE_URL, langDir: "locales/", strategy: "no_prefix", skipSettingLocaleOnNavigate: true, defaultDirection: "ltr", defaultLocale: "tr", detectBrowserLanguage: { useCookie: true, fallbackLocale: "tr", alwaysRedirect: true, cookieSecure: true, redirectOn: "root", cookieKey: "lng" }, locales: [ { code: "tr", iso: "tr-TR", name: "Türkçe", file: "tr.json", dir: "ltr" }, { code: "en", iso: "en-US", name: "English", file: "en.json", dir: "ltr" } ] }
Describe the bug
I work with 2 languages, En and Tr, and I use cookies. It works great when my cookie value is en or tr, but when I change the cookie value manually, it should be tr but it doesn't work. What is my mistake?
i18n: { baseUrl: process.env.BASE_URL, langDir: "locales/", strategy: "no_prefix", skipSettingLocaleOnNavigate: true, defaultDirection: "ltr", defaultLocale: "tr", detectBrowserLanguage: { useCookie: true, fallbackLocale: "tr", alwaysRedirect: true, cookieSecure: true, redirectOn: "root", cookieKey: "lng" }, locales: [ { code: "tr", iso: "tr-TR", name: "Türkçe", file: "tr.json", dir: "ltr" }, { code: "en", iso: "en-US", name: "English", file: "en.json", dir: "ltr" } ] }
Additional context
No response
Logs
No response