Skip to content

fix(frontend): persist UI locale so new tabs keep the selected language - #7580

Open
soroush5 wants to merge 1 commit into
canada-ca:masterfrom
soroush5:fix/persist-locale-new-tab
Open

soroush5 wants to merge 1 commit into
canada-ca:masterfrom
soroush5:fix/persist-locale-new-tab

Conversation

@soroush5

Copy link
Copy Markdown

Fixes #5599.

Switching language with the locale switcher only called i18n.activate() in memory — the choice was never stored anywhere. Every new tab boots through setUpApp, which activates the server default (or the browser language), so the new tab always came up in the default language instead of the one just selected.

This stores the activated locale in localStorage and reads it back at boot, keeping the existing precedence for first-time visitors: stored choice, then APP_DEFAULT_LANGUAGE, then the browser language. If storage is unavailable the app behaves exactly as before.

How to test:

  1. npx jest src/utilities/__tests__/i18nPersistence.test.js in frontend — 4 tests, all fail without the fix and pass with it.
  2. Manual: switch to Français, open any internal link in a new tab — the new tab stays in French. Verified the same flow in headless Chromium against the real i18n.config module: before the fix the second tab read null, after the fix it reads fr.
  3. src/utilities + LocaleSwitcher suites (27 tests) still pass.

@lcampbell2

Copy link
Copy Markdown
Collaborator

/gcbrun

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

Successfully merging this pull request may close these issues.

New tab opens in default user language even if current language is different

2 participants