Web/Desktop: detectLocale() skips English, picks wrong language #8481

Open
opened 2026-02-16 18:10:04 -05:00 by yindo · 2 comments
Owner

Originally created by @andybergon on GitHub (Feb 4, 2026).

Originally assigned to: @adamdotdevin on GitHub.

Bug

The detectLocale() function in the web and desktop apps does not include a check for English (en). It checks for zh, ko, de, es, fr, da, ja, pl, ru, ar, no, pt, and th — but not en. This means English entries in the browser's language list are silently skipped, and the first non-English supported language is selected instead.

Reproduction

Set browser languages to:

en-IE, en-US, en-GB, en, it-IT, it, es

(Accept-Language: en-IE,en-US;q=0.9,en-GB;q=0.8,en;q=0.7,it-IT;q=0.6,it;q=0.5,es;q=0.4)

Expected: UI displays in English (highest priority)
Actual: UI displays in Spanish (lowest priority, q=0.4)

Root cause

detectLocale() iterates through navigator.languages in order but has no startsWith("en") check:

for (const language of languages) {
    if (!language) continue
    // no check for "en" — English entries fall through
    if (language.toLowerCase().startsWith("zh")) ...
    if (language.toLowerCase().startsWith("ko")) return "ko"
    if (language.toLowerCase().startsWith("de")) return "de"
    if (language.toLowerCase().startsWith("es")) return "es"  // ← first match for the example above
    ...
}
return "en"  // ← only reached if NO supported language is found

The loop skips all 4 English entries (en-IE, en-US, en-GB, en), skips it-IT and it (unsupported), then matches es — the least preferred language.

Affected files

  • packages/app/src/context/language.tsx — web app
  • packages/desktop/src/i18n/index.ts — desktop app

(packages/enterprise/src/entry-server.tsx and app.tsx are not affected — they explicitly check for en)

Fix

Add if (language.toLowerCase().startsWith("en")) return "en" as the first check in the loop, before the other language checks.

Originally created by @andybergon on GitHub (Feb 4, 2026). Originally assigned to: @adamdotdevin on GitHub. ## Bug The `detectLocale()` function in the web and desktop apps does not include a check for English (`en`). It checks for `zh`, `ko`, `de`, `es`, `fr`, `da`, `ja`, `pl`, `ru`, `ar`, `no`, `pt`, and `th` — but not `en`. This means English entries in the browser's language list are silently skipped, and the first *non-English* supported language is selected instead. ## Reproduction Set browser languages to: ``` en-IE, en-US, en-GB, en, it-IT, it, es ``` (`Accept-Language: en-IE,en-US;q=0.9,en-GB;q=0.8,en;q=0.7,it-IT;q=0.6,it;q=0.5,es;q=0.4`) **Expected:** UI displays in English (highest priority) **Actual:** UI displays in Spanish (lowest priority, `q=0.4`) ## Root cause `detectLocale()` iterates through `navigator.languages` in order but has no `startsWith("en")` check: ```typescript for (const language of languages) { if (!language) continue // no check for "en" — English entries fall through if (language.toLowerCase().startsWith("zh")) ... if (language.toLowerCase().startsWith("ko")) return "ko" if (language.toLowerCase().startsWith("de")) return "de" if (language.toLowerCase().startsWith("es")) return "es" // ← first match for the example above ... } return "en" // ← only reached if NO supported language is found ``` The loop skips all 4 English entries (`en-IE`, `en-US`, `en-GB`, `en`), skips `it-IT` and `it` (unsupported), then matches `es` — the *least* preferred language. ## Affected files - `packages/app/src/context/language.tsx` — web app - `packages/desktop/src/i18n/index.ts` — desktop app (`packages/enterprise/src/entry-server.tsx` and `app.tsx` are not affected — they explicitly check for `en`) ## Fix Add `if (language.toLowerCase().startsWith("en")) return "en"` as the first check in the loop, before the other language checks.
yindo added the web label 2026-02-16 18:10:04 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 4, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9996: Web UI locale detection can pick a non-English locale even when English is preferred

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 4, 2026): This issue might be a duplicate of existing issues. Please check: - #9996: Web UI locale detection can pick a non-English locale even when English is preferred Feel free to ignore if none of these address your specific case.
Author
Owner

@andybergon commented on GitHub (Feb 4, 2026):

Likely a duplicate of #9996 / #9998.

@andybergon commented on GitHub (Feb 4, 2026): Likely a duplicate of #9996 / #9998.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8481