Skip to content
Draft
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 accepted as its aliases, as on the object-field face.
- **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/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