Skip to content

fix(i18n): respect stored user locale over browser language#938

Open
iMeet07 wants to merge 1 commit intoopenfoodfacts:mainfrom
iMeet07:fix/i18n-respect-user-locale
Open

fix(i18n): respect stored user locale over browser language#938
iMeet07 wants to merge 1 commit intoopenfoodfacts:mainfrom
iMeet07:fix/i18n-respect-user-locale

Conversation

@iMeet07
Copy link

@iMeet07 iMeet07 commented Feb 21, 2026

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:

  • Normalized stored language codes (itit-IT, enen-US)
  • Updated layout logic to prioritize stored user preference over window.navigator.language
  • Ensured correct fallback behavior

Now the selected language persists correctly after refresh.

Fixes unexpected locale override on reload.


Checklist:

Author Self-Review:

  • I have performed a self-review of my own code.
  • I understand the changes I'm proposing and why they are needed.
  • My changes generate no new warnings or errors (linting, console).

LLM Usage Disclosure:

  • I used AI assistance for debugging and reasoning but reviewed and validated the changes manually.

@vercel
Copy link

vercel bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
explorer Ready Ready Preview, Comment Feb 21, 2026 6:39pm

Copy link
Member

@VaiTon VaiTon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already do this in getBrowserLocale, which is called in getLocale. What does this fix?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Let me know when the PR is ready :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants