feat(i18n): use the OS language by default - #324
Rodrigorm33 wants to merge 1 commit into
Conversation
Resolve the initial UI language from the saved choice, then the first supported entry of navigator.languages, then English. Region and script variants map to shipped locales (pt-PT -> pt-BR, nb -> no, zh-HK -> zh-TW). The detected language is not persisted, so the app follows the system language until the user picks one. Closes tonyantony300#282 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016eYokdePRZY5r6GmT5JcqJ
|
|
📝 WalkthroughWalkthroughThe frontend now detects the initial locale from stored preferences and browser language preferences. It matches regional language tags to shipped locales and uses English as the fallback. Tests cover resolution, regional variants, Norwegian, Chinese, and unsupported languages. ChangesLanguage Detection
Assessment against linked issues
Priority: ➖ Normal Change: Feature · Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to After one system-language change, later OS-language changes may no longer update the UI automatically. The issue is bounded and easily worked around manually, but conflicts with the feature’s intended behavior. 🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: ff0fe34e-ecd9-488f-9994-a9044b0044d0
📒 Files selected for processing (4)
frontend/src/i18n/TranslationContext.tsxfrontend/src/i18n/setup.tsfrontend/src/lib/language-detection.test.tsfrontend/src/lib/language-detection.ts
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
| useEffect(() => { | ||
| const handleLanguageChange = () => { | ||
| const newLang = localStorage.getItem('altsendme-language') || 'en' | ||
| const newLang = getInitialLanguage() |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Do not persist a system-detected language.
When languagechange runs without a saved choice, getInitialLanguage() returns the detected locale. The handler then calls i18next.changeLanguage(newLang), and changeLanguage stores that locale under altsendme-language. Because resolveLanguage gives a stored locale priority over system preferences, later OS language changes cannot update the UI.
Apply detected locales without mutating storage. Persist only explicit user selections.
Description
Closes #282
The app now uses the system language when there's a translation for it, and falls back to English otherwise. A language picked manually still wins.
Tested in the browser and on an Android emulator: French and Portuguese open translated, Dutch (no translation) falls back to English. Desktop builds not tested.
Side note, outside this issue: while testing manually on Android, I noticed the screen ends up mixing languages: most text switches to Portuguese, but some strings like "History" stay in English. Those translations are missing from the locale files, so they fall back to English. Happy to open a separate issue.
I used Claude Code to help with this.
Checklist
type(scope): description)pnpm lintbefore raising this PRpnpm formatbefore raising this PR