Repository navigation
Commit 071323e
feat(i18n): a dependent package's fieldPatches text is translated from that package's own translations (#34784)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBFyg5B2muWbKZjA9phXVWse)_
Fixes #33952
Also answers finding #34836 (S1 and N4, both pinned here). That card
holds no claim on this branch, so the area shuts it by hand after the
merge.
Clause-②: yes (widening) — `TranslateDocumentOptions` gains an exported
member, `patchBundles`; nothing accepted before is refused
Metadata-protocol: semantic — a dependent package's translations of its
own `fieldPatches` text now take effect on `/meta` and on the public
form; on a patched slot the pair `.custom` translation is laid over the
package's locale by locale, so a pair that translates the slot only in a
fallback locale (`en`) no longer wins over the package's translation in
the requested one (`zh-CN`)
Skills-docs: follow-up #34785
## 维护者速读
- 改了什么:依赖包用 `fieldPatches` 改写厂商对象字段的标签、说明、选项名后,这些文字现在按该依赖包自己的翻译显示(先
`.custom` 配对包的翻译,再依赖包的,最后原文)。
- 为什么改:之前补丁文字在所有语言下都原样显示英文,依赖包带的 zh-CN 翻译不生效;按卡上裁决 B(6942920667)落地。
- 风险与回滚:只影响被补丁改过的字段文字;没写补丁的字段、租户自改的文字、厂商自己的翻译都不变。Studio
在中文下整体保存时,写入门会把「税号」还原成补丁原文「Tax ID」再存(L2 M1 已修并钉往返测试)。回滚即 revert 本 PR。
- 先看:`packages/spec/src/system/i18n-resolver.ts`(`partCatalog`
选目录的顺序)、`packages/objectql/src/registry-platform-global.ts`(`getPackagedFieldPatchBases`
哪个包写了哪段文字)、`packages/metadata-protocol/src/protocol-discovery-and-bases.ts`(`getPackageTranslationBundle`
读单个包的翻译)。
- 两分钟验证:`pnpm --filter @objectstack/rest exec vitest run
src/meta-object-field-patch-i18n.test.ts`,预期全过,其中 [#33952] 一组断言补丁标签在
zh-CN 下读到「税号」。
- 需要你做的:contract review owed(L2 delta,spec 导出扩展);碰 `packages/spec/src` 走
Tier H 由席位交棒,治理面读数 NOT governed;审核记录在案前不求批。
## What changes
A code package that relabels a vendor's field with `fieldPatches`
(ADR-0146 D10) now has that text translated from its **own**
translations. Before, a patched label, help text, description or option
label was served as the patch wrote it in every locale: a patched slot
read only the pair `.custom` catalog, and the deployment catalog
deep-merges every package's translations with the package ids dropped
(`FileI18nAdapter.loadTranslations`), so the patching package's rows
never reached the slot. Re-measured on `origin/main` dc66d33 before
writing any code: the `/meta` item read served `{"label":"Tax
ID","description":"Unified social credit code."}` under zh-CN with the
dependent's zh-CN rows for both keys in the catalog.
Order on a patched slot, as ruled (6942920667, answering 6931518666):
1. the pair `.custom` package's translation of the key;
2. the translations of the code package whose patch wrote the served
value (its shipped `translations`, then its own active `translation`
rows);
3. the served text.
The owner's translation never applies to a patched slot (#29564 stays
fixed). A slot no patch wrote (a tenant's rename on top) keeps its own
text. Nothing is stamped on the served document: the writing package is
found by comparison, the served value against the packaged base with
that one package's patches applied (ADR-0029 D9.2a).
- `@objectstack/spec` — `TranslateDocumentOptions.patchBundles` (the
name the seat analysis proposed); `translateObject` reads it on a
changed field slot: label, help/description, option label, and through
the same `slotCatalog` also `inlineTitle` and `relatedListTitle`. The
pair is laid over each package's bundle locale by locale along the
fallback chain (the interleaving ruling 6631250894 fixed for unchanged
strings), so a pair that translates a patched slot only in `en` no
longer wins over the package's `zh-CN`.
- `@objectstack/objectql` —
`SchemaRegistry.getPackagedFieldPatchBases(name)`: one entry per enabled
code package whose extension patches the object, highest precedence
first, each the packaged base with only that package's `fieldPatches`
applied. `getPackagedObjectBase` is unchanged and still never folds a
patch in.
- `@objectstack/metadata-protocol` — `getPackagedFieldPatchBases(name)`
(the registry read, feature-detected) and
`getPackageTranslationBundle(packageId)` (one package's translations,
locale-keyed: its installed record's `translations`, then its own active
rows bound by `package_id`).
- `@objectstack/rest` — the `/meta` object item and list reads and `GET
/forms/:slug` pass `patchBundles` (memoised per package across a list
page). The public form passes no `pairBundle` (on `main` too), so there
a patched slot reads package, then text.
- **The save door's inverse** (`restoreTranslatedEchoes`, via
`restoreTranslatedObjectEchoes`; L2 M1 on the first head): it now
translates its sources with the read's `patchBundles` (read through two
new `ProtocolHost` members), and each entry's patched base, cut to the
fields its patch changed, is a source of its own between the stored row
and the platform columns. So a zh-CN Studio GET then whole-body PUT of a
patched label stores the patch text (`Tax ID`), not the package's
translation (`税号`), over a stored row carrying the patch text and with
no stored row; before the fix both stored `税号`, which every locale then
served.
**Five packages became four.** The card expected a per-package
translation copy kept by `II18nService` and the runtime. Read from code,
neither is needed: `registerApp` → `installPackage(manifest)` keeps the
converted manifest, `translations` included, on the package record
(`getPackage(id).manifest`), so the protocol reads a package's own
bundle from the registry. `II18nService` and `packages/runtime` are not
touched. That read is pinned by `registry-field-patch-bases.test.ts` (a
real `ObjectQL.registerApp`, then `getPackageTranslationBundle` over
it).
## Tests
New:
- `packages/spec/src/system/i18n-resolver.object-patch-bundles.test.ts`
(8): patched label/help/option read the patching package's zh-CN; no
`patchBundles` keeps the text; an untranslated locale keeps the patch
text; a tenant rename keeps its text; two patching packages; the pair
keeps the first rank; an entry with no base / no `packagedBase`;
`translateMetadataDocument` passthrough.
- `packages/objectql/src/registry-field-patch-bases.test.ts` (4).
-
`packages/metadata-protocol/src/protocol.package-translation-bundle.test.ts`
(5).
Extended (new `describe` blocks only, no existing assertion changed):
- `packages/rest/src/meta-object-field-patch-i18n.test.ts` (+5).
- `packages/rest/src/public-form-section-i18n.test.ts` (+2).
- `packages/objectql/src/protocol-meta-effective-schema.test.ts` (+2):
the zh-CN GET → PUT round trip on a patched label, with and without a
stored row carrying the patch text; asserts the stored text is `Tax ID`
and an `en` read serves it. Red on the first head `26d09ed6` before the
fix: 2 failed, `expected '税号' to be 'Tax ID'` on the stored label.
- `packages/metadata-protocol/src/protocol-translated-echo.test.ts`
(+3): the pure inverse with `patchBundles` (both sources), a tenant
rename on an unpatched field kept, and no `patchBundles` ⇒ no restore.
Ablations (each restored, blob == HEAD):
- spec: patch rank made inert (`index < patchCatalogs.length` → `index <
0`) → `i18n-resolver.object-patch-bundles.test.ts` 5 failed | 3 passed
(the three green are the keep-own-text cases).
- rest: `patchTranslationBundlesOf` made to return `undefined` → 4
failed | 33 passed across the two rest files (exactly the four [#33952]
serving cases).
- door: `restoreTranslatedObjectEchoes` passes no `patchBundles` → round
trip 2 failed (both legs).
- door: patch-base sources dropped (`[storedDoc, injectedDoc]`) → round
trip 1 failed (no-row leg) | 1 passed (stored-row leg).
- door: the changed-fields cut dropped →
`protocol-translated-echo.test.ts` 1 failed (the tenant-rename case) | 9
passed.
## Acceptance notes
- Out of scope, noted only: object-level `label`/`description` an
extension sets through `objectExtensions` (not `fieldPatches`) may have
the same gap; not measured.
- Not wired here: other `translateObject` callers (validation messages,
formula `label()` and the like) still pass no `patchBundles`, so they
serve a patched slot as before. The `/i18n/translations` detail read was
not re-measured.
- Public form has no pair rank (older than this PR): filed as finding
#34806.
- Not fixed here: a `/meta` conditional read can still answer 304 after
a translation-only change of a patch bundle, since the validator hashes
the served document and locale and no catalog (same standing as the
deployment catalog and pair bundle today).
- Not fixed here: `patchTranslationBundlesOf` and the door issue one
`sys_metadata` read per patching package (filtered in SQL, memoised per
list page), where the pair read folds bindings into one `$in`.
- File surface: beyond the claim, `packages/rest/src/form-routes.ts` +
`public-form-section-i18n.test.ts` (the public form translates the same
object) one paragraph in
`content/docs/data-modeling/object-extensions.mdx`, the two ledger rows
`check:engine-double-contract --write` added to
`scripts/engine-double-contract.pinned.json`, and for M1
`protocol-translated-echo.ts`, `protocol-host.ts` and the host install
in `protocol.ts`.
- Fix round (S1 and N4 of contract review 6948153780, written up as
#34836), head `8510e0e9`: the door's inverse asked a patch entry for a
slot even where the stored row declared that slot with its own text, so
a stored `税号` equal to the patching package's zh-CN translation was
rewritten to `Tax ID` on any whole-body save. Route: the first one
#34836 names. A patch entry now answers a slot only where its patch
changed that slot against the packaged base (per slot, not per field:
N4), and only where the stored row does not declare the slot or carries
the packaged text there (S1). The two pinned legs hold unchanged (a
stored `Tax ID`; no row, so the packaged base is the source). Pins:
`protocol-meta-effective-schema.test.ts` +1 (stored `税号`, an `en`
whole-body save with an unrelated edit to `name`, through the real
`saveMetaItem`: the stored label stays `税号` and the edit lands);
`protocol-translated-echo.test.ts` +3 (the same at the pure layer; N4's
catalog string typed over a tenant-renamed slot is kept; a slot the
patch left alone is no patch source where the stored row does not
declare the field). Ablations through `scripts/ablation-replace.mjs`,
each restored with blob == HEAD: the S1 guard removed, metadata-protocol
rebuilt, dist preflight `--absent` exit 0, gives pure 1 failed / 12
passed and door 1 failed / 24 passed, both `expected 'Tax ID' to be
'税号'`; restored, rebuilt and preflight present gives 13/13 and 25/25.
The per-slot cut removed gives pure 1 failed / 12 passed (`expected
'Registration number' to be '注册号说明'`, the slot-cut pin). The changeset
and the `patchBundles` docblock are unchanged: their wording still
matches. `origin/main` merged (one import-line conflict in
`protocol-discovery-and-bases.ts`, resolved as the union of both). Local
on `8510e0e9`: metadata-protocol 349 passed / 9 skipped, typecheck
green; objectql typecheck green,
`protocol-meta-effective-schema.test.ts` +
`registry-field-patch-bases.test.ts` 29/29; rest patch files 37/37; the
52 gate families derived for this round's three paths all exit 0
(`check:dual-build-cjs-loads` and `check:type-check-debt` first read NOT
MEASURED for want of build state and the lock, then re-run green).
- Round S2 (contract review 6950554757, should-fix), head `70e332e8`:
the stored half of the patch guard in `restoreTranslatedEchoes` was a
second copy of the fold's comparison and differed on an empty string, so
a stored `label: ''` on a patched slot let a zh-CN whole-body save store
`税号` as the tenant's text. It now asks `scalarOverridesPackagedBase`
(imported from `@objectstack/spec/system`) over the packaged field,
option or object that holds the slot, the same call the fold makes. Pin:
`protocol-translated-echo.test.ts` +1 (stored `''`, the zh-CN echo of
the fold's `Tax ID`, restored to `Tax ID`). Ablation through
`scripts/ablation-replace.mjs` (guard put back to the old copy; pure
suite imports `src`, no build): 1 failed / 13 passed, `expected '税号' to
be 'Tax ID'`; restored blob == HEAD `196e74e7`, 14/14 green. Local on
`70e332e8`: metadata-protocol 349 passed / 9 skipped (23103 tests),
typecheck green; objectql door pins 29/29; rest patch files 37/37; 51
gate families derived for this round's two paths, 50 exit 0,
`check:dual-build-cjs-loads` NOT MEASURED (exit 3, no full-repo `dist/`;
CI runs it).
## Verification
All on head `70347ee4` (the M1 rework with `origin/main` merged), on a
shared box:
- Full suites (`pnpm --filter … run test`, under the verify lock), on
`74ab926d` (the merge, before the docblock-only commit): spec 849 files
/ 27178 tests passed; metadata-protocol 349 passed, 9 skipped; objectql
607 / 13612 passed; rest 415 passed; `run typecheck` (incl.
`check:test-typecheck`) green for all four. metadata-protocol re-run on
`70347ee4` after moving two docblocks: 349 passed, 9 skipped; typecheck
green.
- `node scripts/pm/dispatch-gates.mjs --commands`: 129 derived families,
all `exit 0` on `70347ee4`; `--ran` reconciles 129 run, 0 NOT-MEASURED.
The round before it found `check:facade-delegation-only` red
(`protocol.ts` 12 lines over its ceiling once `main` was merged); fixed
by moving the two new reads' docblocks to their facet bodies, leaving
one-line pointers.
- First head `26d09ed6`: 129/129 gates, the same four suites green, CI
72 check-runs green. Two real reds of an earlier round fixed there:
`check:engine-double-contract` and `check:test-source-alias`.
- Premise, before any code, on `origin/main` dc66d33: patched zh-CN
read served `Tax ID` / `Unified social credit code.`; with this branch
the same read serves the dependent's `税号` (pinned in
`meta-object-field-patch-i18n.test.ts`).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmP5nzKTLbaqcH74Nos
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzfr1xZSFZzCR8HnqXX -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8e49847 commit 071323e
20 files changed
Lines changed: 1321 additions & 26 deletions
File tree
- .changeset
- content/docs/data-modeling
- packages
- metadata-protocol/src
- objectql/src
- rest/src
- spec/src/system
- scripts
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
132 | 140 | | |
133 | 141 | | |
134 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
957 | 957 | | |
958 | 958 | | |
959 | 959 | | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
960 | 1055 | | |
961 | 1056 | | |
962 | 1057 | | |
| |||
1036 | 1131 | | |
1037 | 1132 | | |
1038 | 1133 | | |
1039 | | - | |
| 1134 | + | |
1040 | 1135 | | |
1041 | 1136 | | |
1042 | 1137 | | |
| |||
1061 | 1156 | | |
1062 | 1157 | | |
1063 | 1158 | | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
1064 | 1169 | | |
1065 | 1170 | | |
1066 | 1171 | | |
1067 | 1172 | | |
| 1173 | + | |
1068 | 1174 | | |
1069 | 1175 | | |
1070 | 1176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 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 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
0 commit comments