Skip to content

feat(i18n): use the OS language by default - #324

Closed
Rodrigorm33 wants to merge 1 commit into
tonyantony300:mainfrom
Rodrigorm33:fix/282-os-language
Closed

Rodrigorm33 wants to merge 1 commit into
tonyantony300:mainfrom
Rodrigorm33:fix/282-os-language

Conversation

@Rodrigorm33

Copy link
Copy Markdown

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

  • PR title follows Conventional Commits (type(scope): description)
  • I have run pnpm lint before raising this PR
  • I have run pnpm format before raising this PR

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
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Language Detection

Layer / File(s) Summary
Language matching and resolution
frontend/src/lib/language-detection.ts, frontend/src/lib/language-detection.test.ts
Added locale matching for normalized BCP 47 tags, regional variants, Norwegian, and Chinese. Added resolution tests for stored preferences, browser preferences, and fallback behavior.
Initial locale integration
frontend/src/i18n/setup.ts, frontend/src/i18n/TranslationContext.tsx
The i18n setup now resolves the initial locale from stored and browser preferences. Initialization and language changes use getInitialLanguage().

Assessment against linked issues

Objective Addressed Explanation
Automatically apply the system language by default when no language is saved [#282]

Priority: ➖ Normal

Change: Feature · Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 864f1

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)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: ff0fe34e-ecd9-488f-9994-a9044b0044d0

📥 Commits

Reviewing files that changed from the base of the PR and between ccc1eb8 and 864f145.

📒 Files selected for processing (4)
  • frontend/src/i18n/TranslationContext.tsx
  • frontend/src/i18n/setup.ts
  • frontend/src/lib/language-detection.test.ts
  • frontend/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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 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.

@Rodrigorm33
Rodrigorm33 deleted the fix/282-os-language branch September 16, 2026 11:28
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.

Feature request: Use OS language

2 participants