Skip to content

fix(i18n): pick the built-in language when the browser reports it without a region - #2242

Merged
Parvinmh merged 2 commits into
usablica:release-stagingfrom
goranai:fix/i18n-bare-language-tag
Nov 26, 2026
Merged

Parvinmh merged 2 commits into
usablica:release-stagingfrom
goranai:fix/i18n-bare-language-tag

Conversation

@goranai

@goranai goranai commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #2241.

Change

Translator now also matches a language given without a region (fr, de, ru) to the built-in language that starts with it (fr_FR, de_DE, ru_RU). An exact match still wins, and a value with a region that is not built in (sv-SE, de-AT, zh-TW) behaves as before.

Behavior change

Browsers that report one of ar, de, es, fa, fr, it, ja, ko, pt, ru, tr, zh now get that language instead of English. Nothing else changes.

Tests

  • src/i18n/language.test.ts gets cases for fr, de, ES, ru and one for the prefix f. The four language cases fail without the fix.
  • npx jest --ci src/i18n src/packages/tour/option src/packages/hint/option: 37 passed.
  • prettier --check passes on both files.
  • I also ran 1505 values (all two-letter codes in lower and upper case, each built-in code in nine shapes, region variants, empty and odd values) through the old and the new pick. Every value the old code already matched is unchanged. The 38 values that changed are the 12 bare codes above in different casings, and all moved from English to the built-in language.

Validated with Claude Opus 5.5.

@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

@goranai is attempting to deploy a commit to the Pean Team on Vercel.

A member of the Team first needs to authorize it.

… the user

Look the browser language up the way Intl does: for each language of the
user (navigator.languages, most wanted first), take the built-in language
of the same name, otherwise the built-in one of the same language in
another region. So fr-CA gets French, es-MX and es-419 get Spanish, and a
user with ["sv-SE", "de"] gets German instead of English.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Parvinmh

Copy link
Copy Markdown
Contributor

Thanks for this, the bare-tag case is a real problem: Firefox and Chrome often report just de, fr, ja, so the browser-language default rarely worked for them.

I pushed one commit on top (8c73980) to cover the rest of the lookup in the same PR, so the default language changes only once:

  • Regions that are not built in now fall back to the same language: fr-CA → fr_FR, es-MX / es-419 → es_ES, de-AT → de_DE, pt-PT → pt_BR, zh-TW → zh_CN. An exact match still wins (pt-BR → pt_BR).
  • Every language of the user is checked, in order (navigator.languages), not only the first: ["sv-SE", "de"] now gets German instead of English. navigator.language and userLanguage are still used when the list is missing.
  • Your bare-tag behaviour (fr → fr_FR) is unchanged.

Tests: new cases for the regions, the list order and the fallback; full jest 434/434, prettier and tsc clean. Checked in Chromium, Firefox and WebKit with the locale set to fr, fr-CA, de, es-MX, ja, fa, pt-PT, en-GB and sv-SE: the Next button reads Suivant, Suivant, Weiter, Siguiente, 次へ, بعدی, Próximo, Next, Next.

@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
intro-js Ready Ready Preview Nov 26, 2026 7:32am UTC

Request Review

@Parvinmh
Parvinmh merged commit b622d2f into usablica:release-staging Nov 26, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — 8c73980c Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants