Repository navigation
Commit 2068e03
feat(i18n): serve labels by i18n.sourceLocale as the authored language (#34025)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9S57hqQnFxsopofbjbzbR6p)_
Fixes #33634
Clause-②: yes
Metadata-protocol: semantic
Skills-docs: follow-up #34053
## 维护者速读
- 改了什么:运行时现在读取 `i18n.sourceLocale`,把它当作元数据内联标签的原文语言;i18n 服务契约新增可选的
`getSourceLocale` / `setSourceLocale`。
- 为什么改:英文写元数据、默认给用户中文的应用,没配 `fallbackLocale` 时,英文请求拿到的是中文标签;工具已把 `en` 报成
100% 覆盖,运行时却不这么服务。
- 风险与回滚:只影响声明了 `sourceLocale` 的应用;没声明的应用答案逐字不变(每个入口都有对照测试)。回滚即 revert 本
PR。
-
先看:`packages/spec/src/contracts/i18n-service.ts`(新契约方法的语义)、`packages/rest/src/meta-item-read-gate.ts`(元数据读取的取值顺序)、`packages/runtime/src/app-plugin.ts`(声明如何注入服务)。
- 两分钟验证:`pnpm --filter @objectstack/rest exec vitest run
src/meta-i18n-declared-fallback-chain.test.ts`,预期 25 个测试全绿,其中 §6
六个是本卡的钉子。
- 需要你做的:无,席位落地。
## What changes
An app authored in English that defaults its users to `zh-CN`
(`defaultLocale: 'zh-CN'`, `sourceLocale: 'en'`, no `fallbackLocale`, a
`zh-CN` pack) used to serve an `en` request the Chinese row: every
caller that builds the label resolver's options passed
`getDefaultLocale()` as `ResolveOptions.defaultLocale` (the authored
language), so `en` was not "the authored one" and walked the fallback
chain (`zh-CN`, the boot paths' collapse) ahead of the inline text.
Route A of the census report (issuecomment 6894743586), chosen by the
seat:
- **Contract** (`packages/spec/src/contracts/i18n-service.ts`): optional
`getSourceLocale(): string | undefined` and `setSourceLocale(locale):
void`. Same stance as the fallback pair: implementing one does not
oblige the other (per-value); the getter answers only what was declared
and never derives `defaultLocale` — that collapse is the caller's. The
`getDefaultLocale` jsdoc no longer claims it is always the authored
language.
- **Producers**: `AppPlugin.loadTranslations` threads
`i18n.sourceLocale` beside `setDefaultLocale` / `setFallbackLocale`,
guarded on "declared something" (a sibling app on the same kernel keeps
its value). `FileI18nAdapter` and the kernel's in-memory fallback
implement both halves. Measured: `os serve` and plugin-dev construct
`I18nServicePlugin` with `defaultLocale` / `fallbackLocale` only, and
`AppPlugin` then calls the setters on the adapter it built, so neither
boot path needed a new option (`serve.ts`, `dev-i18n.ts` untouched).
- **The five option builders**, each now `getSourceLocale()` (non-empty)
else `getDefaultLocale()` as `ResolveOptions.defaultLocale`, fallback
chain untouched: rest `metaTranslateOptions` (also behind
`RestServer.translateOptionsFor`, `form-routes.ts` and the runtime
dispatcher's list translation), objectql `formula-option-labels.ts`,
plugin-email `option-label-table.ts`, service-analytics
`translateSelectOptions`, service-storage `record-file-access.ts`
`labelsIn`. The census re-run on `895783a1` (every non-test
`fallbackChain` / `getDefaultLocale` reader under `packages/`) found no
sixth builder; the only other `fallbackChain` site is
`ui/packages/i18n/src/utils/spec-formatters.ts`, a client formatter fed
from its own config, not from `II18nService` (noted below).
- **Users'-default readers unchanged**: service-messaging recipient
locale and notification text, runtime `domains/i18n.ts`, discovery,
AppPlugin seed locale, `extractLocale` (a header-less request still
falls to `defaultLocale`), plugin-auth (not touched).
- **Prose made false, corrected in the same PR**:
`TranslationConfigSchema.sourceLocale` jsdoc and `.describe` ("Not yet
read by the serving layer"), `ResolveOptions.defaultLocale` jsdoc and
the resolver header, the `RestServer.translateOptionsFor` docblock, the
regenerated `content/docs/references/system/translation.mdx`, and three
hand-written doc pages that described the old rule or told authors to
add `fallbackLocale: 'en'` as a workaround. Shared read helper: inline
(five 3-line copies); no new `@objectstack/spec/system` export.
## Tests
Each builder has a pin with `defaultLocale: 'zh-CN'`, `sourceLocale:
'en'`, no `fallbackLocale` (collapsed to `zh-CN`): an `en` request
answers the inline English label, a `zh-CN` request the `zh-CN` row, and
a CONTROL with no `sourceLocale` keeps today's answer (`zh-CN` row for
`en`).
- rest `meta-i18n-declared-fallback-chain.test.ts` §6: single read, list
read, header-less request (falls to `zh-CN`), a third locale (`ja-JP`
walks the chain to `zh-CN`), controls with the accessor absent and
answering `undefined`.
- objectql `engine-formula-option-label.test.ts`, plugin-email
`template-option-labels.integration.test.ts` (booted kernel),
service-analytics `picklist-dimension-label-i18n.test.ts` (both
strategies), service-storage `record-file-access.integration.test.ts`
(the upload-link page, English and Chinese).
- Producers: `fallbacks.test.ts` (memory provider),
`file-i18n-adapter.test.ts`, `app-plugin.test.ts` (threads, does not
call when undeclared, skips a provider without the setter), spec
`i18n-service.test.ts`.
- Forced test edits: none. Two harness widenings to reach the pins: the
rest file's `protocol()` / `makeRest()` take an optional document map,
and the plugin-email `AppFixture` takes accessor overrides; every
existing case runs with the defaults it had.
<details><summary>Readings (local, shared container; packages built at
the head the suites ran on)</summary>
- Full suites, the nine consumer packages (downstream direction: the
packages that read the widened contract), one locked run: spec 842 files
/ 26958 tests, core 147 / 3404, objectql 596 / 13174, service-i18n 4 /
73, plugin-email 53 / 1020, service-analytics 215 / 5220 (335 skipped),
service-storage 86 / 1652 (1 skipped), rest 412 / 8448 (332 skipped),
runtime 605 / 10961 (19 skipped): all passed. Typecheck green in all
nine (runtime's test layer after building `driver-turso`, a
devDependency outside the first build closure).
- Ablation, one per changed builder plus the producer
(`scripts/ablation-replace.mjs`, mutation proven on disk, file restored
to its HEAD blob each time): rest source read removed → 2 of 25 red (§6
single and list read); objectql → 1 of 9 red; plugin-email → 1 of 4 red;
service-analytics → 2 of 30 red (one per strategy); service-storage → 1
of 90 red; `AppPlugin` `setSourceLocale` call removed → 1 of 39 red.
Each test file imports the source under test, so no rebuild was needed
for the legs.
- `pnpm --filter @objectstack/spec check:generated`: one stale artifact
(`content/docs/references/system/translation.mdx`), regenerated;
`api-surface` unchanged (an optional interface member).
</details>
## Acceptance notes
- `ui/packages/i18n/src/utils/spec-formatters.ts` builds a
`fallbackChain` from its own client config, not from `II18nService`; it
is outside this route (the Console's own locale config). Not filed.
- A regional request in the source language (`en-US` against
`sourceLocale: 'en'`) is not recognised as the authored one:
`isDefaultLocale` compares tags exactly (case-insensitive), the same as
it always did for `defaultLocale`. Unchanged by this PR; noted, not
filed.
## Verification
Verification head: `b63efd08`, a merge-only commit of `origin/main`
(`e71ecc1b`, 15 commits past the previous merge) made under the seat's K
≥ 15 landing rule; CI on this head is the landing verdict. No file this
PR changes moved on main's side. The local readings below were taken at
`5156e558` (suites, ablations, derived gates, HTTP door) and `74a2954d`
(the first merge of `main`: full rebuild, `check:generated` green with
nothing to regenerate).
<details><summary>HTTP door, booted</summary>
The todo example in a side worktree at this head, set to `defaultLocale:
'zh-CN'`, `sourceLocale: 'en'`, no `fallbackLocale`, and its `en` bundle
dropped (so English can only come from the inline labels); `pnpm dev
--fresh`, signed in as the dev admin, `GET
/api/v1/meta/object/todo_task`:
- `Accept-Language: en` → `Task` / `Tasks` / field `Subject` (inline
English)
- `Accept-Language: zh-CN` → `任务` / `任务` / `主题`
- `Accept-Language: ja-JP` → `タスク` / `タスク` / `件名`
- no header → `任务` (the users' default)
- CONTROL, same stack without `sourceLocale`: `en` → `任务` / `任务` / `主题`
(the card's defect, unchanged for a stack that declares nothing).
The example edits lived only in that throwaway worktree; it was removed
after both servers were stopped.
</details>
<details><summary>Derived gates (head 5156e55)</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` on head `5156e558`: 130 commands, all run,
all exit 0; `--ran` reconciliation: 130 derived, 130 run, 0
NOT-MEASURED, 0 UNRUN. The first round (head `75656a8b`) found one real
red, `check:test-source-alias` on the edited rest test (the routes reach
`@objectstack/objectql` through a dynamic import inside a case's clock);
fixed in `5156e558` with a module-top `import '@objectstack/objectql'`,
the shape the package's other door tests use. Its other two non-zero
exits were environment: `check-plugin-teardown-shape --self-test` exit 3
until its pinned commit was fetched into the shallow clone, and
`check:generated`'s embedded `check:test-typecheck` tsc run failing
without diagnostics at the default heap (green at the CI heap, 4096 MB).
</details>
<!-- signed: domain:spec#2 · os-steve · session_01ADHkmRFB7DnbZ57susY8Uv
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent fa1fb6f commit 2068e03
28 files changed
Lines changed: 562 additions & 70 deletions
File tree
- .changeset
- content/docs
- kernel
- protocol/kernel
- references/system
- ui
- packages
- core/src/fallbacks
- objectql/src
- plugins/plugin-email/src
- rest/src
- runtime/src
- services
- service-analytics/src
- __tests__
- service-i18n/src
- service-storage/src
- spec/src
- contracts
- system
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
488 | | - | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
489 | 492 | | |
490 | | - | |
491 | | - | |
| 493 | + | |
| 494 | + | |
492 | 495 | | |
493 | | - | |
| 496 | + | |
494 | 497 | | |
495 | 498 | | |
496 | | - | |
| 499 | + | |
497 | 500 | | |
498 | 501 | | |
499 | 502 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
542 | | - | |
| 542 | + | |
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
192 | | - | |
193 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
| |||
372 | 373 | | |
373 | 374 | | |
374 | 375 | | |
375 | | - | |
376 | | - | |
377 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
378 | 379 | | |
379 | 380 | | |
380 | 381 | | |
| |||
400 | 401 | | |
401 | 402 | | |
402 | 403 | | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
409 | 410 | | |
410 | 411 | | |
411 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
660 | 660 | | |
661 | 661 | | |
662 | 662 | | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
663 | 685 | | |
664 | 686 | | |
665 | 687 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
109 | 115 | | |
110 | 116 | | |
111 | 117 | | |
| |||
257 | 263 | | |
258 | 264 | | |
259 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
260 | 283 | | |
261 | 284 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
621 | 621 | | |
622 | 622 | | |
623 | 623 | | |
| 624 | + | |
624 | 625 | | |
625 | 626 | | |
626 | 627 | | |
| |||
2544 | 2545 | | |
2545 | 2546 | | |
2546 | 2547 | | |
| 2548 | + | |
2547 | 2549 | | |
2548 | 2550 | | |
2549 | 2551 | | |
| |||
0 commit comments