Skip to content

fix(i18n): system locale extensions no longer hide Brazilian Portuguese - #46059

Open
saphid wants to merge 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-840674f795
Open

saphid wants to merge 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-840674f795

Conversation

@saphid

@saphid saphid commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Problem

When a browser, phone, or OS reports Brazilian Portuguese with a Unicode locale extension (for example pt-BR-u-nu-latn), the System language setting loads English or the next preferred language instead of the installed pt-BR catalog. The shared matcher in packages/client-runtime/src/locales.ts compared the whole tag, then only the bare language (pt), and neither equals pt-BR. Web passes navigator.languages straight in (apps/web/src/i18n/runtime.ts → resolveWebLocaleSelection), as do mobile (I18nProvider) and Electron main (desktop/src/i18n/messages.ts).

Deterministic repro on origin/main (95a3ec546411b62869d36a8f45ae2eaf91ddb769), from the checkout root:

import { resolveLocaleSelection } from "./packages/client-runtime/src/locales.ts";
resolveLocaleSelection("system", ["pt-BR-u-nu-latn", "en-GB"], ["en", "pt-BR"], "en");
  • Observed: { catalogLocale: "en", formattingLocale: "en-GB" } (bare ["pt-BR", "en-GB"] gives pt-BR).
  • Expected: { catalogLocale: "pt-BR", formattingLocale: "pt-BR-u-nu-latn" }.

In the web app: set navigator.languages to ["pt-BR-u-nu-latn", "en-GB"] and choose System default; on main the UI stays English, with the fix document.lang is pt-BR and Settings reads "Configurações".

Change

The shared matcher also compares the tag without its BCP 47 extensions (everything from the first single-character subtag) before falling back to the bare language. The original tag is still used for formatting. pt-PT still does not map to pt-BR, and Traditional Chinese handling is unchanged. Because web, mobile, and Electron main all use this matcher, the one change fixes all three.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • apps/web/src/i18n/locales.test.ts gets three cases: pt-BR-u-nu-latn, mixed-case PT-br-u-nu-latn, and a pt-PT negative control. On base, the two extension cases fail (catalogLocale "en" instead of "pt-BR"). On head, all 8 pass.
  • vp run check:changed exits 0 (format, lint, knip, typecheck, tests).
  • Before/after Node transcript: https://gist.github.com/saphid/9db8a366ed7cce13c54827af3224cbab

Not shown: browser screenshots of the localized UI, a mobile device run, and a packaged Electron run. All three use the shared resolver tested above.

Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • apps/web/src/i18n/runtime.ts:63 — No before/after browser capture is linked. For a reproducible browser check, set Firefox’s intl.accept_languages to pt-BR-u-nu-latn,en-GB before loading T3, select System default, and check document.documentElement.lang and the Settings breadcrumb. Firefox exposes this preference through navigator.languages. citeturn367312view1
  • apps/web/src/i18n/locales.ts:13 — Clarify that the shared resolver returns the extended formatting tag to mobile; web leaves system formatting to the host and Electron main consumes only the catalog. The Node transcript does not demonstrate a formatting change on web or Electron.
  • .github/pull_request_template.md:26 — The supplied summary reports vp run check:changed exit 0, but the linked transcript does not include that run or identify the tested head. Add the head SHA and check summary to the evidence.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 30, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 30, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at d0f873c

Macroscope's review found this PR approvable — Locale matching now recognizes Brazilian Portuguese and other supported locales when system tags contain extensions or underscores. Explicit language choices and existing fallback behavior remain unchanged.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The locale matcher now normalizes underscores to hyphens and checks supported locales against both the normalized tag and its base before a BCP 47 extension. Tests cover Portuguese selection, formatting locale normalization, and English fallback.

Changes: Locale matching

Layer / File(s) Summary
Locale normalization and matching
packages/client-runtime/src/locales.ts, packages/client-runtime/src/locales.test.ts
The matcher normalizes underscores to hyphens, checks the full tag and its extension-free base, and updates the Traditional Chinese pattern for hyphen-separated tags. Tests cover Portuguese catalog selection, formatting locale normalization, and English fallbacks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to d0f87

This change makes system locales with extensions, such as pt-BR-u-nu-latn, select the installed pt-BR catalog while keeping the original tag for formatting. The change is small and covered by regression tests. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: system locale extensions no longer hide Brazilian Portuguese. The raw summary and objectives confirm that the matcher now strips BCP 47 extensions before the bare-language …
Description check Passed The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section gives a reproduction on a specific commit, expected and observed results, and the affected …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: system locale extensions no longer hide Brazilian Portuguese. The raw summary and objectives confirm that the matcher now strips BCP 47 extensions before the bare-language fallback, so pt-BR-u-nu-latn resolves to the pt-BR catalog. The title is specific and matches the main change. It is a conventional commit title in plain language.

Full details: Description check

Explanation

The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section gives a reproduction on a specific commit, expected and observed results, and the affected entry points. The Change section explains the matcher fix and the pt-PT and Traditional Chinese handling. The Scope section justifies the absence of an issue. The Verification section lists focused tests, a check run, and a transcript, and it states what was not shown. Remaining gaps: the template asks for the model and harness used, and the reviewer notes say the check run is not tied to a tested head SHA in the transcript and that formatting behavior on web and Electron is not demonstrated. These are non-critical, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d94ee86 and d0f873c.

Files selected for processing: 2

  • packages/client-runtime/src/locales.test.ts
  • packages/client-runtime/src/locales.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 30, 2026
juliusmarminge and others added 2 commits November 30, 2026 13:03
…resolver

Underscore system tags such as pt_BR-u-nu-latn never reached the
extension-stripped exact match, so normalize separators first. Move the
regression cases next to the shared resolver, where they also check the
original tag is kept for formatting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@macroscopeapp
macroscopeapp Bot dismissed their stale review November 30, 2026 13:06

Dismissing prior approval to re-evaluate d0f873c

@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). and removed size:XS 0-9 changed lines (additions + deletions). labels Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). takeover:in-progress A takeover lead is working on this PR vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants