Repository navigation
Commit a058413
fix(i18n): the Console language menu offers the platform locale table's languages (#31793)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbQ445c6fbGTJdveorKb6FDj)_
Fixes #30514
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — the published `objectstack-i18n` skill never says
the Console menu offers a locale outside the platform table, and every
`supportedLocales` example in it is a table language
## 维护者速读
- **改了什么**:Console 右上角语言菜单只提供平台语言表(11 种)里的语言,并与应用声明的语言取交集。`zh-CN`
这类旧写法显示成表里的名字(简体中文),同一语言只出现一次,`th` 这类表外语言不再出现。
- **为什么改**:裁决 F
规定平台只有一张语言表、不分档。此前菜单把应用列表原样照搬:所有自带应用都显示「中文(中国)」,还会提供没有任何界面翻译的 `th`。
- **风险与回滚**:这是一次收窄,受影响的自带应用为 0 个(examples 三个应用和 HotCRM 只声明表内语言)。已存储 `th`
的用户会先以 `th` 启动,应用列表到达后自动回到默认语言。回滚只需 revert 本 PR,无数据迁移。
- **先看**:`ui/packages/i18n/src/provider.tsx`(`offeredTableTags`
与自愈判断),`ui/packages/app-shell/src/layout/LocaleSwitcher.tsx`(勾选),`ui/apps/console/src/pages/system/ProfilePage.tsx`(存储值读法)。
- **两分钟验证**:`cd ui && pnpm exec vitest run
packages/app-shell/src/layout/__tests__/LocaleSwitcher.appLocales.test.tsx`,预期全部通过,其中
app-crm、app-todo、HotCRM 三种声明都显示表内名称。
- **需要你做的**:无,席位落地(落地前席位需完成契约复审档复核)。
## What changes
`offerableLanguages` (the list the globe menu and the profile page's
language card render) is now the platform locale table ∩ the app's
locale list:
- each code the app lists (`GET /api/v1/i18n/locales`) is read through
`resolveBuiltInLanguage`, which applies the table's read aliases and
then shorter prefixes, the same resolution that picks the pack the code
renders in;
- only codes that land on a table tag are kept, as that tag,
de-duplicated, in the app's declared order;
- an app answer with no table language, or no `loadLocales` wiring,
offers the table's 11 tags. An out-of-table key of `config.resources` no
longer adds an entry to that fallback.
Around it:
- **Self-heal.** The `provisional` self-heal (a stored language accepted
on the loader's credit) is judged against the offered set, not the raw
app list. A stored `th` still boots, then reverts and is cleared once
the list lands, even when the app lists `th`. The loader's credit and
`BootstrapLocaleOptions.hasLoader` are unchanged (seat amendment 2,
option C).
- **Checkmark.** `LocaleSwitcher` compares the session language through
`resolveBuiltInLanguage`, so a session in `zh-CN` ticks 简体中文.
- **Profile page.** `ProfilePage` reads a stored `sys_user.locale`
spelling as its table tag (`zh-CN` → `zh-Hans`). Without that, the
exact-match check prepended a stray 中文(中国) option beside 简体中文. A tag the
table does not name stays as stored.
### What the menu offered before, measured
Probe on `origin/main` c2bb879: the real `I18nProvider` with a mocked
`loadLocales`. Step-1 report: #30514 comment 6731426750.
| Case | `loadLocales()` answer | Before | After |
|:--|:--|:--|:--|
| 1 · no loader (control) | none | 11 table tags | unchanged |
| 2a · table tags | `en, zh-Hans` | English, 简体中文 | unchanged |
| 2b · app-crm, app-showcase | `en, zh-CN` | English, 中文(中国) | English,
简体中文 |
| 2c · app-todo | `en, zh-CN, ja-JP` | …, 日本語 (日本) | …, 日本語 |
| 2d · HotCRM sales | `en, zh-CN, ja-JP, es-ES` | …, Español de España |
…, Español |
| 3 · out-of-table | `en, zh-CN, th` | …, ไทย (no pack) | English, 简体中文
|
| 4a · alias beside its tag | `en, zh-CN, zh-Hans` | two entries for one
pack | one 简体中文 |
| 4b · region variants | `de-AT, pt-PT, zh-TW, en-GB` | CLDR names
(Português europeu served by `pt-BR`) | `de`, `pt-BR`, `zh-Hant`, `en`
with table labels |
| 5 · app declares nothing | the loaded bundle set | 11 entries, mixed
spellings | the 11 table tags |
### Narrowing census: 0 first-party apps affected
- `supportedLocales` declarations: examples/app-crm `['en', 'zh-CN']`,
examples/app-showcase `['en', 'zh-CN']`, examples/app-todo `['en',
'zh-CN', 'ja-JP']`, HotCRM `src/sales/index.ts` `['en', 'zh-CN',
'ja-JP', 'es-ES']`. objectstack-ai/gallery declares none.
- None names a language outside the table, and no example or HotCRM
translations file is keyed outside it.
- 0 in-repo producers pass `config.resources` to `I18nProvider` (`git
grep` over `ui/apps`, `ui/packages`, `ui/examples`).
### Downstream readers of the offered tag
A pick now writes the table tag (`zh-Hans`). `zh-Hans` was already an
offered value before this PR, in cases 1, 2a and 5. Each reader accepts
it, measured:
- **The html lang attribute.** The provider writes
`document.documentElement.lang = lng`, and the end-to-end pin's DOM
shows `lang="zh-Hans"`.
- **The locale header the adapter sends.** `createAuthenticatedFetch`
copies the html lang attribute into `Accept-Language`. Both i18n
providers resolve a request locale with `resolveLocaleAmong`, and
`resolveLocaleAmong('zh-Hans', [en, zh-CN, ja-JP, es-ES, …])` = `zh-CN`,
`ja` → `ja-JP`, `es` → `es-ES`.
- **What gets stored back to `sys_user.locale`.** The column's
`locale_bcp47_shape` rule (`SYS_USER_LOCALE_TAG_PATTERN`) accepts
`zh-Hans`, `zh-Hant` and `pt-BR`. The messaging reader uses the same
shape, and its bundle ladder is the same `resolveLocaleAmong`.
## Why
Ruling F (#29428, of #29349): the platform supports one list of
languages, each complete on every surface, with no tiers. Phases 2 and 3
completed the Console packs and the server bundles for the table's 11
languages. This phase makes the menu offer exactly those languages.
## Tests
On `ui/` as of `bbc447f4`, from `ui/`, under
`scripts/pm/os-verify-lock.sh`:
- `packages/i18n/src/__tests__/`,
`packages/app-shell/src/layout/__tests__/LocaleSwitcher*`,
`apps/console/src/pages/system/__tests__/ProfilePage*`: Test Files
107/107, Tests 1873 passed, 13 skipped.
- Consumers of the offered list
(`app-shell/src/hooks/__tests__/userLocale*`, `AppHeader*`,
`studio-locale.i18n`, console `i18nAfterSignIn-12034`, `loadLocales*`,
`FirstRunChecklist`, `HomeLayout.searchOpensPalette-12601`,
`sharedInboxFeed.twoSurfaces`, plugin-form `affordanceGrantMap-12082`):
46 files. 45 were green; `userLocale-10059` went red as expected and is
the edited pin below, and that file now passes 24/24.
New and rewritten pins:
- `LocaleSwitcher.appLocales.test.tsx`
- `th` is not offered, whether it comes from the app list or from
`config.resources`;
- the app-crm / app-todo / HotCRM declarations show table labels, once
each;
- `zh-CN` beside `zh-Hans` is one entry;
- a session stored as `zh-CN` ticks 简体中文.
- `provider-app-locale-restore.test.tsx`
- a stored `th` boots, then reverts and is purged once the list lands;
- a stored `zh-CN` stays and is offered as `zh-Hans`;
- table ∩ app list as tags in app order; region variants;
- the table fallback for an app listing no table language;
- CONTROL: no loader offers the 11 table tags.
- `ProfilePage.language.test.tsx` (new top-level describe)
- a stored `zh-CN` is one option with nothing to save;
- a stored `th` is still shown.
Edited pin, approved by the seat: `userLocale-10059.test.tsx` "renders
the offered variant for a bare column, end to end". A `zh` column with
`loadLocales` `['en','zh-CN']` now shows `zh-Hans` (before: `zh-CN`).
The offered entry is now the table tag; the pack is the same.
Ablation of the canonicalizing step (`offeredTableTags` pushes the raw
code instead of its table tag), through `scripts/ablation-replace.mjs`:
- the anchor went x1 → x0, and the blob went `c7299ca5` → `2551b42e`;
- 11 tests failed across `provider-app-locale-restore` and
`LocaleSwitcher.appLocales` (Tests 11 failed, 22 passed);
- the restore left the blob equal to HEAD with `git diff HEAD` empty.
## Acceptance notes
- **Ruling F gaps outside this card**, carried on #29428 by the seat:
- (a) the Studio namespace ships 2 of 11 languages, and `zh-Hant`
resolves to the Simplified catalogue;
- (b) the built-in emails ship 4 of 11 locales;
- (c) `TranslationConfigSchema` accepts an out-of-table
`supportedLocales` entry.
This PR adds no language anywhere. It only removes entries.
- `localeLabel`'s `Intl.DisplayNames` branch is now reached only for a
code outside the table, which the menu no longer offers. It is left in
place: it is exported and still named by its own tests.
## Verification
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 36 commands. All 36 were run and
exited 0, and `--ran` reconciles 36 derived / 36 run / 0 NOT-MEASURED.
The PR-body gates (`check-changeset-no-major`,
`check-adr-0087-registration`, `check-closing-keyword-parity`,
`check-partof-closing-keyword`) ran against this body and exited 0.
- `pnpm --filter @object-ui/i18n run type-check` exited 0. The app-shell
and console type-checks are left to CI's Type Check UI (they need the
whole `ui/` closure built).
- Head `96d210d4` merges `origin/main`. The incoming commits touch no
file in this diff, and `ui/` is unchanged since `bbc447f4`, where the
suites above ran.
- The full dogfood battery is owed for the `(narrowing)` arm. It is
running on `96d210d4`, and its reading goes in the os-dev-report on
#30514.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(`packages/spec` untouched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (`eslint` over the seven
touched `ui/` files: 0 errors; the repo-wide run is CI's)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jRuaxwwjABz1AXpCeM)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 34a30e8 commit a058413
8 files changed
Lines changed: 267 additions & 84 deletions
File tree
- .changeset
- ui
- apps/console/src/pages/system
- __tests__
- packages
- app-shell/src
- hooks/__tests__
- layout
- __tests__
- i18n/src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
584 | | - | |
585 | | - | |
| 584 | + | |
| 585 | + | |
586 | 586 | | |
587 | 587 | | |
588 | 588 | | |
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
622 | 630 | | |
623 | 631 | | |
624 | 632 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
| 349 | + | |
| 350 | + | |
350 | 351 | | |
351 | 352 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
92 | 97 | | |
93 | 98 | | |
94 | 99 | | |
| |||
117 | 122 | | |
118 | 123 | | |
119 | 124 | | |
120 | | - | |
| 125 | + | |
121 | 126 | | |
122 | 127 | | |
123 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
23 | | - | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| |||
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
77 | | - | |
| 80 | + | |
78 | 81 | | |
79 | 82 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
83 | 87 | | |
| 88 | + | |
84 | 89 | | |
85 | 90 | | |
86 | | - | |
| 91 | + | |
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
92 | 97 | | |
93 | | - | |
94 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
95 | 135 | | |
96 | 136 | | |
97 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
21 | 26 | | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
| |||
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
59 | 75 | | |
60 | 76 | | |
61 | 77 | | |
| |||
153 | 169 | | |
154 | 170 | | |
155 | 171 | | |
156 | | - | |
157 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
158 | 195 | | |
159 | | - | |
| 196 | + | |
160 | 197 | | |
161 | 198 | | |
162 | 199 | | |
| |||
170 | 207 | | |
171 | 208 | | |
172 | 209 | | |
173 | | - | |
| 210 | + | |
174 | 211 | | |
175 | 212 | | |
176 | 213 | | |
| |||
201 | 238 | | |
202 | 239 | | |
203 | 240 | | |
204 | | - | |
| 241 | + | |
205 | 242 | | |
206 | 243 | | |
207 | 244 | | |
| |||
0 commit comments