Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/36950-metadata-form-option-labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/spec': minor
'@objectstack/lint': patch
'@objectstack/platform-objects': patch
---

feat(spec): a Studio metadata form's select choices are translatable — `metadataForms.<type>.fields.<path>.options.<value>`

Clause-②: yes (widening)
Metadata-protocol: added

- **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.
- **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.
- **Extraction.** `os i18n extract` and `pnpm check:i18n` emit the new `options.<value>` keys for every form row that lists `options`.
- **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.
6 changes: 3 additions & 3 deletions content/docs/protocol/kernel/i18n-standard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ through the one the renderer reads for that node:

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

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

Because the server resolves this group, the bundle a console downloads when it
opens — `GET /api/v1/i18n/translations/:locale` — leaves `metadataForms` out:
Expand Down
6 changes: 3 additions & 3 deletions content/docs/references/system/translation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ Translation data for a single object
| **label** | `string` | optional | Translated metadata-type display label (overrides registry label) |
| **description** | `string` | optional | Translated metadata-type description |
| **sections** | `Record<string, { label?: string; description?: string }>` | optional | Section translations keyed by section.name |
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
| **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) |

### Nested Shape: `PlatformTranslationData.settingsCommon`

Expand Down Expand Up @@ -796,7 +796,7 @@ Translation data for a single object
| **label** | `string` | optional | Translated metadata-type display label (overrides registry label) |
| **description** | `string` | optional | Translated metadata-type description |
| **sections** | `Record<string, { label?: string; description?: string }>` | optional | Section translations keyed by section.name |
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
| **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) |

### Nested Shape: `TranslationData.settingsCommon`

Expand Down Expand Up @@ -1019,7 +1019,7 @@ Translation data for a single object
| **label** | `string` | optional | Translated metadata-type display label (overrides registry label) |
| **description** | `string` | optional | Translated metadata-type description |
| **sections** | `Record<string, { label?: string; description?: string }>` | optional | Section translations keyed by section.name |
| **fields** | `Record<string, { label?: string; helpText?: string; placeholder?: string }>` | optional | Field translations keyed by field path (dot-notation for nested fields) |
| **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) |

### Nested Shape: `TranslationItem.settingsCommon`

Expand Down
9 changes: 9 additions & 0 deletions packages/lint/src/i18n-walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,7 @@ function walkHookTexts(config: any, out: ExpectedEntry[]): void {
* metadataForms.<type>.fields.<dotPath>.label
* metadataForms.<type>.fields.<dotPath>.helpText
* metadataForms.<type>.fields.<dotPath>.placeholder
* metadataForms.<type>.fields.<dotPath>.options.<value>
*
* Section names follow the same normalization rule the resolver uses when
* `section.name` is absent: `label.toLowerCase().replace(/&/g,'and').replace(/[^a-z0-9]+/g,'_').replace(/^_+|_+$/g,'')`.
Expand Down Expand Up @@ -2789,6 +2790,14 @@ function walkFormField(field: any, type: string, parentPath: string, out: Expect
pushEntry(out, ['metadataForms', type, 'fields', path, 'label'], inlineText(field.label) ?? humanizeFieldPath(path), 'metadataFormField', { metadataType: type });
pushOptional(out, ['metadataForms', type, 'fields', path, 'helpText'], field.helpText, 'metadataFormField', { metadataType: type });
pushOptional(out, ['metadataForms', type, 'fields', path, 'placeholder'], field.placeholder, 'metadataFormField', { metadataType: type });
// A select's choices, keyed by value — the key `translateFormField`
// overlays onto `options[].label`.
if (Array.isArray(field.options)) {
for (const option of field.options) {
if (!option || typeof option !== 'object' || typeof option.value !== 'string') continue;
pushEntry(out, ['metadataForms', type, 'fields', path, 'options', option.value], option.label, 'metadataFormField', { metadataType: type });
}
}
}
if (Array.isArray(field.fields)) {
for (const child of field.fields) walkFormField(child, type, path, out);
Expand Down
Loading
Loading