Repository navigation
fix(i18n): a region-tagged code loads its base built-in catalogue (objectui#11326) - #11367
Conversation
…jectui#11326) The built-in catalogues are keyed by base language (`zh`) while the platform, the Console's language menu and the stored choice speak full BCP-47 tags (`zh-CN`). `isBuiltInLanguage` and `loadBuiltInLocale` looked a code up exactly, so a stored `zh-CN` never fetched the `zh` catalogue and every built-in string rendered through the `en` fallback on each page load. One exact-then-base normaliser, `matchLanguageTag`, now lives in the registry. `isBuiltInLanguage`, `isBuiltInLocaleLoaded` and `loadBuiltInLocale` read it through `resolveBuiltInLanguage`; a catalogue is fetched and memoised under its own code, so `zh` and `zh-CN` share one fetch. `resolveSeedLanguage` reuses the same function instead of its inline copy. The three provider call sites are untouched. Claude-Session: https://claude.ai/code/session_01VhxTqosz7wn54ahqyxgERT Co-authored-by: Claude <noreply@anthropic.com>
|
changeset-claim-re-read
|
✅ Console Performance Budget
The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it. 📦 Bundle Size Report
Size Limits
|
Contract reviewServed-tier: Reviewed 2026-10-01T08:54Z from: card #11326 (body and all four comments), PR #11367 (body, file list, and the net diff against ① Derived judgmentsThe widening — three entry exports (
The language preserved — judged from the pins. "keeps the user's tag" and "switching to
Derived effects through
The seed rows. Seven assertions in six rows of The mount effect's side-effect, stated by the PR: for a stored region tag it adds a One over-broad sentence, not blocking: ② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
…jectui#11168 slice 3, round 4) origin/main d0fba91 (#11346, #11359, #11361, #11367). It touches pnpm-lock.yaml, which this branch also edits (the plugin-tree devDependency link); no conflict. Claude-Session: https://claude.ai/code/session_01VhxTqosz7wn54ahqyxgERT Co-authored-by: Claude <noreply@anthropic.com>
Fixes #11326
Clause-②: yes
What this changes
@object-ui/i18nkeys its built-in catalogues by base language (zh). The platform, the Console's language menu and the stored choice all use full BCP-47 tags (zh-CN).isBuiltInLanguageandloadBuiltInLocalelooked a code up exactly, so a storedzh-CNnever fetched thezhcatalogue, and every built-in string rendered through theenfallback on each full page load.matchLanguageTag(tag, has)inpackages/i18n/src/locales/registry.tsis now the only exact-then-base implementation in the package.resolveBuiltInLanguage(lang)applies it to the catalogue keys.isBuiltInLanguageandloadBuiltInLocaleread it, which are the ruling's two.isBuiltInLocaleLoadedreads it too; see deviation 1.zhandzh-CNshare one fetch, andgetLoadedBuiltInLocales()stays keyed by catalogue code, which is howcreateI18nand the app-shell splash read it.resolveSeedLanguagereuses it. Its inline split is replaced by onematchLanguageTag(seed, ...)call whose predicate askscanResolveLanguage(code, config).canResolveLanguagestays the seed's only verdict, as its docblock requires.provider.tsxcall sites are untouched. These arepreloadBootstrapLocale, the mount effect andchangeLanguage, and each call-site line is present once at base and once at head. Theprovider.tsxdiff has three hunks: thematchLanguageTagimport, point 1 ofresolveSeedLanguage's docblock (which said region subtags are "normalised away" and would now be false), and that function's body. Occurrences of the base-language split:provider.tsx2 → 0,registry.ts0 → 1. No fallback is copied into a call site; the one copy that existed moved into the registry.Unchanged:
xx-YY,tlh) is refused exactly as before.import()specifier moved. Shipped source has 0 changed import lines; the only import-adjacent change is one added named binding from the already-imported./locales/registry.js.Measured hypotheses
mainsources: 7 failed, 3 passed. Every failure is the stated mechanism:loadBuiltInLocale('zh-CN')givesexpected null not to be null, the provider rendersexpected 'Save' to be '保存', and the preload leaveszhnot resident. The 3 passing rows are the controls:enresolves,xx-YYandtlhare refused, and a storedenrenders English.LAZY_LOCALE_LOADERSholdszh ja ko de fr es pt ru ar, withenresident. No key is a full tag, so the exact-wins half is pinned on the normaliser itself (pt-BRwins overpt,pt-PTfalls topt) and on every real catalogue code resolving to itself, which a futurezh-TWwould inherit.zh-CN, and afterchangeLanguage('zh-CN'), the provider'slanguage, the document'slangattribute and the stored value are allzh-CN, and the strings come fromzh.isBuiltInLanguage('xx-YY')andisBuiltInLanguage('tlh')arefalse, and the loader givesnullfor both.Why the provider pin takes a fresh module graph. The DOM projects make all ten catalogues resident (
vitest.setup.i18n-catalogues.ts). Withzhresident, i18next answers azh-CNlookup out of thezhbundle through its own language hierarchy, so a pin in that state passes on the broken code.vi.resetModules()gives back the state a page load has:enresident and nothing else.Deviations, stated rather than silent
isBuiltInLocaleLoadedis a third reader. It is the same file and the same rule. Left exact, it would answerfalseforzh-CNwhileloadBuiltInLocale('zh-CN')resolves with no fetch, which contradicts its own docblock ("no fetch needed"). Zero callers in this repository. That makes three exported functions that now accept a region-tagged code, not two.zh-CN, notzh. Seven assertions in six rows ofprovider-tenant-locale-seed.test.tsxmove fromzhtozh-CN, and in one row fromjatoja-JP. Each row still asserts what it was written for; the row about the pack the tag reaches now also asserts保存. This is the direct consequence of the ruling: onceisBuiltInLanguage('zh-CN')is true,canResolveLanguageaccepts the exact tag. Keepingzhwould need a second, exact-only "do we have this locale" predicate, whichresolveSeedLanguage's docblock forbids. It is raised as an open question to the seat, with the alternative..changeset/7479-lazy-locale-catalogues.mdgets a dated, append-only correction. Its "nullfor a code this package does not ship" is now false forzh-CN. The base blob is a byte-identical prefix of the head blob (cmpexit 0, 4501 base bytes, 571 appended), and the frontmatter md5 is identical.Tests, at
c2f59cf4apnpm exec vitest run packages/i18n/plus 14 consumer files that boot, seed, store or switch to a region-tagged locale (inapps/console,examples/console-starter,app-shell,auth,componentsandplugin-charts). Result: 89 files passed, 1317 passed, 13 skipped.Reverse verification on the committed state.
registry.tsandprovider.tsxwere checked out from base under an EXIT/INT/TERM trap with absolute paths. On disk,matchLanguageTagwent 3 → 0 and the registry blob equals the base blob. The final pin file then ran 10 failed, 3 passed:expectedthe catalogueto be null, because at basezh-CNgivesnullwhilezhgives the catalogue;TypeError ... is not a function, because the export does not exist at base;The restore came from
HEAD. Both hashes equal theHEADblobs andgit diff HEADis empty. The pin imports../provider.jsand../locales/registry.jsrelatively, so the subject resolves tosrc/; nodistis on the path and no rebuild was needed.Gates, at
c2f59cf4apnpm --filter '@object-ui/i18n^...' build(types, core): exit 0.@object-ui/i18n:build(with dist completeness) exit 0;type-check(script echoed,tsc --noEmit && tsc -p tsconfig.test.json) exit 0;lintexit 0. Nothing ineslint.config.jsis type-aware, and CI'spnpm lintruns each package'seslint ., so this is CI's lint verdict for every touched TypeScript file.check:control-bytes,check:new-line-citations(with--baseset to the branch point),check:changeset-claims,check:pending-changeset-literals,check-changeset-presence,check-changeset-no-major,check:doc-fences,check:i18n-keys,check:test-path-roots,check:unreferenced-sources.check-governed-queue-guard --test: NOT GOVERNED.check:readme-exports. Its population collapsed because 33 of 40 packages are unbuilt in this worktree, which is a could-not-run and not a verdict. No finding in that run namespackages/i18n/README.md. Left to CI.check:doc-snippets. The full gate needs 34 package closures built, which is CI's run. A narrowed measurement was taken instead: the one edited README block compiles--strictagainst the built@object-ui/i18ndist (exit 0), and a negative control withisBuiltInLanguage(42)fails withTS2345(exit 2).check:eager-locale-cataloguesandcheck:eager-closure. Both need a full console production build. Shipped source changes noimport()specifier and theLAZY_LOCALE_LOADERSblock is unchanged; the source-shape pinentry-locale-shape-7479.test.tspassed in the run above.Docs
packages/i18n/README.mdbuilt-in locales block states the lookup rule and thezh-CNexample, and the persistence paragraph says a storedzh-CNis kept as written.content/docs/guide/troubleshooting.md§8 step 3 notes that built-in catalogues are looked up exact tag first, then base language..changeset/11326-i18n-region-locale-fallback.md:@object-ui/i18nminor, with the widening stated.Acceptance notes
These are observations only; none was filed. Each was read from source, not measured through a public entry point.
getResourceBundle(currentLang)by the exact tag. It therefore adds azh-CNbundle that duplicates the residentzhone, which costs one extra re-render of every reader at mount. Avoiding it needs a change at that call site, which the ruling excluded. Carrier: none.pickInitialLanguage) still strips to the base (ja-JP→ja), while the stored and seed tiers now keep the full tag. Carrier: none.isRTLmatches exactly.isRTLchecksRTL_LANGUAGESexactly, soar-EGreads as left-to-right. This is the same family. No producer of anar-*tag was found; the showcase offersenandzh-CN. Carrier: none.@object-ui/app-shell'spickRenderableLocalekeeps its own copy of the order.matchLanguageTagis deliberately not on the package entry; the ruling kept it registry-internal. Carrier: none.LocaleSwitchermarks the active entry by exactlanguage === code. A host withoutloadLocalesoffers bare codes, so a storedzh-CNshows no checkmark there. The Console wiresloadLocalesand offerszh-CN. Carrier: none.zh-TWgets Simplified. A region tag with no full-tag catalogue gets its base:zh-TWreads the Simplifiedzhcatalogue. That is i18next's own hierarchy and the order the seed already used.matchLanguageTagandresolveBuiltInLanguageare reachable through the./locales/*wildcard subpath (@object-ui/i18n/locales/registry), asregisterBuiltInLocalealready is. They are not on the package entry.Same-family cards whose content is out of scope: objectui#10862, objectui#10969 and objectui#10748 are about missing catalogue rows. They remain open, and nothing here touches them.
Generated by Claude Code