fix(i18n): respect stored user locale over browser language#938
fix(i18n): respect stored user locale over browser language#938iMeet07 wants to merge 1 commit intoopenfoodfacts:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
VaiTon
left a comment
There was a problem hiding this comment.
I can't reproduce the original issue. Beside this, why are it-IT and en-US hardcoded?
|
|
||
| const normalized = stored === 'it' ? 'it-IT' : stored === 'en' ? 'en-US' : stored; | ||
|
|
||
| const finalLocale = normalized || window.navigator.language || 'en-US'; |
There was a problem hiding this comment.
We already do this in getBrowserLocale, which is called in getLocale. What does this fix?
There was a problem hiding this comment.
Thanks for the feedback.
The issue I observed was that when preferences.lang stored a short code like "it", it didn’t match the registered locales ("it-IT"), causing fallback to "en-US" on refresh.
Instead of handling this in +layout.ts, I will move the normalization into getBrowserLocale() to avoid duplication and keep locale resolution centralized.
There was a problem hiding this comment.
Thank you! Let me know when the PR is ready :)
Description
This PR fixes an issue where the application always reset the locale to the browser language on refresh, ignoring the user's previously selected language stored in preferences.
Changes:
it→it-IT,en→en-US)window.navigator.languageNow the selected language persists correctly after refresh.
Fixes unexpected locale override on reload.
Checklist:
Author Self-Review:
LLM Usage Disclosure: