feat(i18n): try browser language before English fallback#9060
feat(i18n): try browser language before English fallback#9060emsplendit wants to merge 2 commits into
Conversation
When localStorage has no valid 'userLanguage' entry, the i18n store now consults navigator.languages and selects the first supported match instead of going straight to the English fallback. Region subtags fall through (e.g. es-AR -> es). Behavior for users with an existing localStorage preference is unchanged.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughinitializeLanguage() now falls back to browser-preference detection when localStorage contains no valid locale; a new detectBrowserLanguage() scans navigator.languages (then navigator.language) for supported exact matches and base-language fallbacks. setLanguage(lng, persistPreference = true) can now skip persisting the choice to localStorage. ChangesBrowser Language Detection Fallback
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/i18n/src/store/index.ts`:
- Around line 64-71: The initialization currently calls setLanguage(detected)
and setLanguage(FALLBACK_LANGUAGE) which persist to localStorage; change this so
auto-detected or fallback locales are applied without persisting. Add an
optional persist flag to setLanguage (e.g., setLanguage(lang: string, persist =
true)) or add a helper applyLanguageWithoutPersist, update calls from
detectBrowserLanguage and the fallback path to call with persist = false (or use
the new helper), and ensure setLanguage still persists when called by explicit
user preference flows.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 190429f9-b35f-4eee-aec1-b41104f0354e
📒 Files selected for processing (1)
packages/i18n/src/store/index.ts
setLanguage() previously always wrote to localStorage, turning the auto-detect and fallback paths into a one-shot stamp. Add a persistPreference flag (default true) and pass false from initializeLanguage so the browser preference is re-evaluated on each visit until the user makes an explicit choice. Per CodeRabbit review.
|
Closing this PR. #8898 migrated I'll open a fresh PR against the post-#8898 codebase that does the same thing — try Thanks for the reviews so far. |
Description
Self-hosted Plane instances currently always boot every user into English on first visit. This PR changes the i18n initialization so that, when no saved
userLanguagepreference exists inlocalStorage, the store consultsnavigator.languagesand selects the first supported match before falling back to English.Selection priority (new behavior in bold):
localStorage["userLanguage"]if it holds a supported code (unchanged)navigator.languages(ornavigator.languageas fallback), with regional fallthrough — e.g.pt-BRmatches exactly,es-ARfalls through toesFALLBACK_LANGUAGE(English) (unchanged)Once a user explicitly picks a language, the choice is persisted to
localStorageas before and takes precedence on future visits. Behavior for users with an existing saved preference is therefore unchanged.Scope of the change
packages/i18n/src/store/index.tsdetectBrowserLanguage()(~25 lines)initializeLanguage(), between the localStorage check and the English fallbacktypeof navigator === "undefined")Type of Change
Screenshots and Media (if applicable)
N/A — the change is invisible to anyone who already has a saved language preference, and new visitors simply land in their browser's locale instead of English.
Test Scenarios
Manually verified the four meaningful cases. The
@plane/i18npackage has no test infrastructure (no jest/vitest in devDependencies, notestscript), so this PR is code-only; happy to bootstrap a test setup if reviewers want one, but that's arguably a separate concern.navigator.languages = ["es-AR", "es", "en"], no localStorage entry → loads in Spanishnavigator.languages = ["fr-CA", "fr"], no localStorage entry → loads in Frenchnavigator.languages = ["xx-YY"](unsupported), no localStorage entry → falls through to EnglishuserLanguage=jaalready → loads Japanese, browser preference ignored (unchanged behavior)References
No existing open issue matches exactly. Closest tangentially-related is #8581 ("DateTime Format is not taking effect"), about date/time format persistence rather than UI language. Happy to file a tracking issue first if maintainers prefer that workflow.
Summary by CodeRabbit
New Features
Behavior Change