Skip to content

Commit dedc16c

Browse files
feat(spec): Studio metadata-form select choices are translatable (metadataForms options slot) (#37569)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuPE7uyDAJyqjwwMzomWv5ff)_ Fixes #36950 Clause-②: yes (widening) Metadata-protocol: added Skills-docs: none — `skills/objectstack-i18n/SKILL.md` names the `metadataForms` group only, never its leaf keys; the group is platform-owned, so no app author writes the new key ## 维护者速读 - 用户能看到什么变化:非英文的搭建者在 Studio 里打开对象、字段、报表、仪表盘、钩子、动作、页面、智能体、技能的配置表单时,下拉框里的选项名(例如共享模型「私有 — 仅所有者」、字段类型、删除行为、默认时间段)改为显示当前语言;以前这些选项在所有语言下都是英文,周围的字段名却已经翻译。 - 为什么做:翻译包里没有放选项名的位置,服务端也不翻译它们。 - 出错会怎样:只多翻译一层显示文字,选项的值不变,保存下来的数据不变;某个选项没有译文时仍显示原来的英文。 - 要你做什么:这个 PR 改动约 3,790 行(主要是 10 种语言的译文),超过 3,000 行,按规则需要授权审批人批准后由座位落地。 ## What changes **The reading the card asked for** (at `021524cd`, `METADATA_FORM_REGISTRY` walked with the extractor's path rule): of the 18 registered Studio forms, 9 carry a select row with `options` — `object`, `field`, `hook`, `report`, `dashboard`, `action`, `page`, `agent`, `skill` — 38 rows, 187 options (185 distinct `type.path.value` keys: `object`'s `fields.deleteBehavior` is listed twice, with the same names). Every one is seen by a builder: the console's `SchemaForm` renders `fieldSpec.options` ahead of the schema enum (`ui/packages/app-shell/src/views/metadata-admin/SchemaForm.tsx`, the enum/select branch), and the server translated only `label`, `helpText` and `placeholder` of a form field. - **Spec, translation slot** (`packages/spec/src/system/translation.zod.ts`). A `metadataForms.<type>.fields.<path>` entry accepts `options`: a record from option `value` to its translated name, the shape `objects.<object>.fields.<field>.options` already has. `choices` and `values` are refused there, as on the object-field face, and the refusal names `options` as the key to write (the `aliases` row of the strict object is the rename hint of that unknown-key refusal, not an accepted spelling). - **Spec, resolver** (`packages/spec/src/system/i18n-resolver.ts`). `translateFormField` overlays each `options[]` entry's `label` with the translation keyed by its `value`, along the locale chain; an option with no translation, or with a non-string value, is passed through unchanged. This is the walker `resolveMetadataFormLabels` uses, which `/api/v1/meta/types` localizes served forms with. - **Lint, extractor** (`packages/lint/src/i18n-walk.ts`). `walkFormField` emits `metadataForms.<type>.fields.<path>.options.<value>` for every option of a row, seeded with its English label, so `os i18n extract` and `pnpm check:i18n` offer exactly the keys the resolver reads. - **Platform-objects, shipped locales.** `node scripts/check-i18n-bundles.mjs --write` added the 185 keys to all eleven `*.metadata-forms.generated.ts` packs; the ten translated packs then got hand-written names (ar, de, es-ES, fr, ja-JP, ko, pt-BR, ru, zh-CN, zh-Hant) and a second `--write` dropped every source-hash row they had seeded. The 17 Default Period choices take the wording of the console's own period chip (`ui/packages/i18n/src/locales/*`, `dashboard.filters.range.*` and `dashboard.filters.custom`), so the period an author picks reads as the period a viewer sees. Loanwords that read the same as English (`URL`, `HTML`, `JSON`, `Markdown`, and per locale words such as de `Text`, fr `Date`) are spelled so they are not byte-echoes of the source, which the catalog's zero-echo pins require (`object-lifecycle-panel-echo-decisions.test.ts`, `report-form-echo-decisions.test.ts`): for example zh-CN `网址(URL)`, de `Textfeld`, fr `Date (sans heure)`. - `content/docs/references/system/translation.mdx` regenerated (`gen:docs`). Small calls made here (no card): the rename hints for `choices` / `values` mirror the object-field face; a non-string option value is passed through untouched rather than stringified, since every option a registered form lists has a string value (the reading found none other). ## Why A non-English builder saw a translated field label with English choices under it on every server-rendered Studio form. The bundle had no slot for the names, so no locale could fix it. ## Verification - `packages/spec/src/system/i18n-resolver.test.ts`, new top-level describe "select option names": a choice is renamed by its value and keeps its other keys; a value with no translation keeps its English label; a nested repeater row is reached by its dot path; the input form is not mutated. - `packages/platform-objects/src/metadata-translations/form-option-labels.test.ts` (new): through the SERVED bundle and the real registry, the object form's sharing model reads `私有 — 仅所有者` in zh-CN; the reading floor (≥30 option rows over ≥8 forms) holds; for each of the ten translated locales every choice of every form select has a non-empty name that differs from its English label. - Local runs on this branch: `packages/spec` full suite green (vitest, 618 s); `packages/lint` 236 files / 9,680 tests green; `packages/platform-objects` translations + metadata-translations 29 files green; `packages/cli` `test/i18n-extract.test.ts` green; `node scripts/check-i18n-bundles.mjs` exit 0; `pnpm check:i18n-coverage` could not measure here (exit 3: the example apps are not built in this worktree), so CI carries that one; `pnpm --filter @objectstack/spec check:generated` exit 0 after `gen:docs`. - `node scripts/pm/overlap-check.mjs` exit 0 against `origin/main` and the open PRs sharing these files (#37422, #37366). Contract review (L2) is owed before landing: the diff changes `packages/spec/src/**` and declares `Clause-②: yes (widening)`. Changed lines exceed 3,000, so landing needs an authorized approval. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [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: its generated artifacts are regenerated and committed. - [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 with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgUpnvPnJ1hR74pUrVj)_ <!-- signed: repo:objectstack#2 · os-sales · session_01L6bhgUpnvPnJ1hR74pUrVj --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6b7b305 commit dedc16c

19 files changed

Lines changed: 3463 additions & 416 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/lint': patch
4+
'@objectstack/platform-objects': patch
5+
---
6+
7+
feat(spec): a Studio metadata form's select choices are translatable — `metadataForms.<type>.fields.<path>.options.<value>`
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: added
11+
12+
- **Translation slot.** A `metadataForms.<type>.fields.<path>` entry accepts `options`, a map from option `value` to its translated name — the shape `objects.<object>.fields.<field>.options` already uses. `choices` and `values` are refused there, as on the object-field face, and the refusal names `options` as the key to write.
13+
- **Served forms.** `resolveMetadataFormLabels` (what `/api/v1/meta/types` localizes forms with) now overlays each option's `label` with the translation keyed by its `value`; an option with no translation keeps its own label. Before this, a select on a Studio metadata form (sharing model, ownership, field type, delete behaviour, default period, …) showed English choice names in every locale while the label and help text around it were translated.
14+
- **Extraction.** `os i18n extract` and `pnpm check:i18n` emit the new `options.<value>` keys for every form row that lists `options`.
15+
- **Shipped locales.** The ten translated metadata-forms packs of `@objectstack/platform-objects` name all 185 choices (38 select rows across nine forms). The Default Period choices reuse the wording of the console's period chip.

‎content/docs/protocol/kernel/i18n-standard.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ through the one the renderer reads for that node:
572572

573573
| Node | What the panel reads | Resolver |
574574
|:---|:---|:---|
575-
| a form field, a composite's child | `FormFieldSpec.label` / `helpText` / `placeholder` | `resolveMetadataFormLabels(form, type, bundle, opts)` |
575+
| a form field, a composite's child | `FormFieldSpec.label` / `helpText` / `placeholder`, and each `options[].label` by its `value` | `resolveMetadataFormLabels(form, type, bundle, opts)` |
576576
| a property of a repeater row (a table column header) | the JSON Schema `items.properties[k].title` | `resolveMetadataFormSchemaTitles(schema, type, bundle, opts)` |
577577
| a column of the type's Studio list (`METADATA_LIST_REGISTRY`) | the served `list.columns[].label` | `resolveMetadataListLabels(list, type, bundle, opts)` |
578578

@@ -583,8 +583,8 @@ a column path the form does not declare, with the column's header as the source.
583583
All three run in `GET /api/v1/meta`, which serves every type's `form`, `list`
584584
and `schema` already localised for the request's locale; a client deriving the schema itself
585585
with `z.toJSONSchema` applies the second one to its own copy, over a bundle it
586-
carries itself. Only `label` crosses over to the schema (as `title`); `helpText`
587-
and `placeholder` stay on the form.
586+
carries itself. Only `label` crosses over to the schema (as `title`); `helpText`,
587+
`placeholder` and the option names stay on the form.
588588

589589
Because the server resolves this group, the bundle a console downloads when it
590590
opens — `GET /api/v1/i18n/translations/:locale` — leaves `metadataForms` out:

‎content/docs/references/system/translation.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ Translation data for a single object
359359
| **label** | `string` | optional | Translated metadata-type display label (overrides registry label) |
360360
| **description** | `string` | optional | Translated metadata-type description |
361361
| **sections** | `Record<string, { label?: string; description?: string }>` | optional | Section translations keyed by section.name |
362-
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
362+
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string; options?: Record<string, string> }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
363363

364364
### Nested Shape: `PlatformTranslationData.settingsCommon`
365365

@@ -806,7 +806,7 @@ Translation data for a single object
806806
| **label** | `string` | optional | Translated metadata-type display label (overrides registry label) |
807807
| **description** | `string` | optional | Translated metadata-type description |
808808
| **sections** | `Record<string, { label?: string; description?: string }>` | optional | Section translations keyed by section.name |
809-
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
809+
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string; options?: Record<string, string> }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
810810

811811
### Nested Shape: `TranslationData.settingsCommon`
812812

@@ -1030,7 +1030,7 @@ Translation data for a single object
10301030
| **label** | `string` | optional | Translated metadata-type display label (overrides registry label) |
10311031
| **description** | `string` | optional | Translated metadata-type description |
10321032
| **sections** | `Record<string, { label?: string; description?: string }>` | optional | Section translations keyed by section.name |
1033-
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
1033+
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string; options?: Record<string, string> }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
10341034

10351035
### Nested Shape: `TranslationItem.settingsCommon`
10361036

‎packages/lint/src/i18n-walk.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,6 +2753,7 @@ function walkHookTexts(config: any, out: ExpectedEntry[]): void {
27532753
* metadataForms.<type>.fields.<dotPath>.label
27542754
* metadataForms.<type>.fields.<dotPath>.helpText
27552755
* metadataForms.<type>.fields.<dotPath>.placeholder
2756+
* metadataForms.<type>.fields.<dotPath>.options.<value>
27562757
*
27572758
* Section names follow the same normalization rule the resolver uses when
27582759
* `section.name` is absent: `label.toLowerCase().replace(/&/g,'and').replace(/[^a-z0-9]+/g,'_').replace(/^_+|_+$/g,'')`.
@@ -2819,6 +2820,14 @@ function walkFormField(field: any, type: string, parentPath: string, out: Expect
28192820
pushEntry(out, ['metadataForms', type, 'fields', path, 'label'], inlineText(field.label) ?? humanizeFieldPath(path), 'metadataFormField', { metadataType: type });
28202821
pushOptional(out, ['metadataForms', type, 'fields', path, 'helpText'], field.helpText, 'metadataFormField', { metadataType: type });
28212822
pushOptional(out, ['metadataForms', type, 'fields', path, 'placeholder'], field.placeholder, 'metadataFormField', { metadataType: type });
2823+
// A select's choices, keyed by value — the key `translateFormField`
2824+
// overlays onto `options[].label`.
2825+
if (Array.isArray(field.options)) {
2826+
for (const option of field.options) {
2827+
if (!option || typeof option !== 'object' || typeof option.value !== 'string') continue;
2828+
pushEntry(out, ['metadataForms', type, 'fields', path, 'options', option.value], option.label, 'metadataFormField', { metadataType: type });
2829+
}
2830+
}
28222831
}
28232832
if (Array.isArray(field.fields)) {
28242833
for (const child of field.fields) walkFormField(child, type, path, out);

0 commit comments

Comments
 (0)