Repository navigation
fix(i18n): pick the built-in language when the browser reports it without a region - #2242
Conversation
|
@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>
|
Thanks for this, the bare-tag case is a real problem: Firefox and Chrome often report just 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:
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. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Fixes #2241.
Change
Translatornow 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,zhnow get that language instead of English. Nothing else changes.Tests
src/i18n/language.test.tsgets cases forfr,de,ES,ruand one for the prefixf. The four language cases fail without the fix.npx jest --ci src/i18n src/packages/tour/option src/packages/hint/option: 37 passed.prettier --checkpasses on both files.Validated with Claude Opus 5.5.