Skip to content

fix(app-shell): match sys_user.locale in the server resolveLocale order - #30150

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-30050-console-locale-match
Nov 5, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-30050-console-locale-match

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Refs #30050 (half 2)

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:控制台按用户的 sys_user.locale 选界面语言时,改用与服务端 resolveLocale 相同的匹配顺序(精确 → 忽略大小写 → 基础语言 → 同语言变体)。
  • 为什么改:原来只做精确匹配和基础语言匹配。存成 zh-cn 的历史行,或 zh / zh-Hans-CN 这类标签,在部署只提供 zh-CN 时匹配不到,中文用户看到的是英文界面。
  • 风险与回滚:只改 pickRenderableLocale 一个纯函数,不碰服务端和数据;回滚即还原这一个提交。匹配不到的语言仍然什么都不切换,与原行为一致。
  • 先看:ui/packages/app-shell/src/hooks/useUserLocale.ts 的 pickRenderableLocale(四步匹配);ui/packages/app-shell/src/hooks/__tests__/userLocale-10059.test.tsx 末尾新增的 describe。
  • 两分钟验证:在 ui/ 下跑 pnpm exec vitest run packages/app-shell/src/hooks/__tests__/userLocale-10059.test.tsx,预期 18 条全部通过,其中 zh-cn、zh、zh-Hans-CN 都解析到 zh-CN,en-GB 解析到 en。
  • 需要你做的:无,席位落地。

What changes

pickRenderableLocale picks the console's UI language for a signed-in user's sys_user.locale. It now resolves in the same order as the server's i18n routes, which use resolveLocale in packages/core fallbacks/memory-i18n.ts:

  1. exact tag;
  2. the same tag in any case (zh-cn → zh-CN). This covers a row written before the server door folded case: such rows are not migrated and are served as stored;
  3. base language, in any case (en-GB → en; zh-CN → zh when a zh pack is offered);
  4. the first offered variant of the base language (zh → zh-CN, zh-Hans-CN → zh-CN).

A match returns the offered spelling. A tag that shares no language with any offered locale still matches nothing, so the device language keeps deciding, as before.

The matcher stays in app-shell. @objectstack/core exports resolveLocale, but app-shell does not depend on it, and it is a server kernel package. The @object-ui/i18n matchLanguageTag takes a predicate, not a list, so it cannot express the variant step. Widening it would also change the seed and catalogue lookups, which this card does not cover.

Tests

A new top-level describe in the existing harness userLocale-10059.test.tsx pins these cases:

  • case fold;
  • bare language to variant;
  • script-tagged tag to variant;
  • unoffered region to base;
  • base preferred over a sibling variant;
  • first offered variant wins;
  • an unknown tag and an empty list give no match;
  • end to end: I18nProvider mounted with loadLocales answering ['en', 'zh-CN'] and a column of zh renders zh-CN.

The existing pickRenderableLocale cases are kept unchanged: exact pt-BR, zh-CN → zh, th refused, and the list still in flight.

All runs below are on head 218415004 (git rev-parse --short HEAD), from the worktree, after the final commit.

app-shell locale suite: 18/18 pass

pnpm exec vitest run --maxWorkers=2 packages/app-shell/src/hooks/__tests__/userLocale-10059.test.tsx (from ui/, under the verify lock)

 Test Files  1 passed (1)
      Tests  18 passed (18)
os-verify-lock: VERDICT command-exit 0
Reverse verification: the origin/main matcher turns 6 of the 8 new pins red

With the fix committed, useUserLocale.ts was restored from merge base 55337f4ce in the tree only. On disk that left 0 caseMatch lines and 1 offerable.includes(base) line. The suite was re-run, then the file was restored with git checkout HEAD -- under a trap. After the restore, the file hash matched the HEAD blob dd0da66e and git diff HEAD was empty.

     x folds case to the offered spelling (a legacy mis-cased row)
     x expands a bare language to the offered variant
     x reaches the offered variant through a script-tagged tag
     x falls back to the base language for an unoffered region
     x takes the first offered variant when several share a base
     x renders the offered variant for a bare column, end to end
      Tests  6 failed | 12 passed (18)
os-verify-lock: VERDICT command-exit 1

Two of the new pins are expected to stay green on the old code, because both behaviours already held before: base over variant (pt-PT → pt) and no match (th-TH, xx-YY, empty list).

Type-check: app-shell

pnpm exec turbo run type-check --concurrency=2 --filter=./ui/packages/app-shell ran tsc --noEmit && tsc -p tsconfig.test.json. Result: Tasks: 68 successful, 68 total, VERDICT command-exit 0.

Acceptance notes

  • The matcher copies resolveLocale's order rather than importing it, for the dependency reasons given under What changes.
  • @object-ui/i18n's seed and catalogue lookup (matchLanguageTag) still matches exact, then base, with no case fold. The built-in packs are keyed by base language (zh), so a mis-cased seed such as zh-cn still reaches zh through the base step. No wrong answer was reproduced, so this is noted here and not filed.
  • Half 1 of the card (the server door in plugin-auth) is not touched. Triage did not file it.

Verification

The gate list was derived with node scripts/pm/dispatch-gates.mjs --commands, which took the change set from the merge base 55337f4ce (3 paths). It named 35 families. All 35 ran locally on head 218415004 and every one exited 0; exit codes were captured before any pipe. The --ran reconciliation reads 35 derived, 35 run, 0 NOT-MEASURED, 0 UNRUN.

Per-family exit codes
0  node scripts/check-adr-0087-registration.mjs --base origin/main
0  node scripts/check-adr-0087-registration.mjs --self-test
0  node scripts/check-changeset-no-major.mjs --base origin/main
0  node scripts/check-closing-keyword-parity.mjs
0  node scripts/check-closing-keyword-parity.mjs --self-test
0  node scripts/check-comment-mask-corpus.mjs
0  node scripts/check-empty-changeset.mjs --base origin/main
0  node scripts/check-empty-changeset.mjs --self-test
0  node scripts/check-sdui-manifest.mjs
0  node scripts/check-sdui-manifest.mjs --self-test
0  node scripts/pm/release-rehearsal-clone.mjs --self-test
0  node scripts/release-pending-publish.mjs --self-test
0  pnpm --filter @objectstack/spec run check:duration-unit-keys
0  each of the 21 pnpm check:* families, check:changeset-gate-self-tests through check:where-matcher
0  pnpm --dir ui exec vitest run scripts/   (Test Files 170 passed, 2 skipped; Tests 4985 passed, 2 skipped)

The derivation lists five CI type-check lanes that it cannot place locally. Those are left to CI.


Generated by Claude Code

Exact, then case-insensitive, then base language, then the first offered
variant, so a legacy mis-cased row and a bare or script-tagged tag reach
the offered locale instead of rendering English.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYpFBMr917PmVkG9up7
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#3 · os-justin · session_01QSeKYpFBMr917PmVkG9up7

Progress · 2026-11-04T20:02Z · answering triage's Request: progress 6640771334


Generated by Claude Code

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 5, 2026 00:36
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 5, 2026 00:36
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit d3edfb5 Nov 5, 2026
56 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-30050-console-locale-match branch November 5, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant