diff --git a/.changeset/36528-related-list-label-translation.md b/.changeset/36528-related-list-label-translation.md new file mode 100644 index 00000000000..576b13884da --- /dev/null +++ b/.changeset/36528-related-list-label-translation.md @@ -0,0 +1,31 @@ +--- +'@objectstack/spec': minor +'@objectstack/lint': minor +'@objectstack/metadata-protocol': minor +'@objectstack/objectql': minor +--- + +feat: a record-page tab title an object's `relatedLists` entry declares can be translated + +Clause-②: yes (widening) +Metadata-protocol: added + +An object-form `relatedLists` entry (`{ list, label, columns }`) titles its tab and table on the parent's record page, and its `label` wins over the child lookup field's `relatedListTitle`. The field's title had a translation key; the entry's did not, so a declared tab title showed its authored text in every locale. + +A translation bundle now carries it on the parent object, keyed by the entry's literal `list` (a dotted `object.field` is one key): + +```ts +objects: { + account: { + _relatedLists: { + contact: { label: '联系人' }, + 'event.related_to': { label: '会议' }, + }, + }, +} +``` + +- `@objectstack/spec`: `ObjectTranslationDataSchema._relatedLists` (a closed leaf with one key, `label`; the un-prefixed `relatedLists` is named as a rename onto `_relatedLists`). `translateObject` overlays it onto the served parent object's entries, so `GET /meta/object` serves the translated title and the console's record page shows it with no change of its own. Only an entry that authors a `label` is translated: an entry without one, a bare name and a built-in tab keep their current title (the child field's `relatedListTitle`, else the child object's plural label). A title a tenant changed keeps its text, as every other translated slot does. +- `@objectstack/lint`: `os i18n extract` scaffolds the key for every labelled entry and the coverage gate counts it; `os validate` reports a `_relatedLists` key that names no labelled entry of that object as `translation-target-unknown`. A labelled entry an object extension brings (a list placement in `place`, or a shown entry of the paired `.custom` package's `relatedLists`) is a labelled entry of the object it extends, so its key resolves; the record page shows a placed tab only where that object declares `relatedLists`. A key over a built-in tab, or over an entry the `.custom` arrangement hides, is reported with its own reason. +- `@objectstack/metadata-protocol`: a save that sends back a translated entry title (a Studio edit of the object read in another language) stores the source title instead, with an `info` advisory, as it already does for field labels. +- `@objectstack/objectql`: the packaged base `getPackagedObjectBase` hands the `/meta` read (the text a served slot is compared with) carries the tabs a code package's `place` adds to the owner's `relatedLists`, as the fold splices them (so only where the owner declares `relatedLists`). A placed title is therefore translated from the deployment's catalog, which carries the placing package's translations, the way a field such a package adds already is; a tenant's rename of that title keeps its text. A `.custom` arrangement's title is the customization layer and reads the pair's own translations. diff --git a/content/docs/protocol/kernel/i18n-standard.mdx b/content/docs/protocol/kernel/i18n-standard.mdx index 30368dc3014..56347ce7918 100644 --- a/content/docs/protocol/kernel/i18n-standard.mdx +++ b/content/docs/protocol/kernel/i18n-standard.mdx @@ -369,6 +369,7 @@ const zh: TranslationData = { }, _views: { all_accounts: { label: '全部客户' } }, _sections: { basic_info: { label: '基本信息' } }, + _relatedLists: { contact: { label: '联系人' } }, // a relatedLists entry's own label _actions: { convert: { label: '转换', confirmText: '确认转换?' } }, }, }, @@ -1168,6 +1169,7 @@ beneath an action entry are judged the same way under either. | `objects.{object}._views.{view}` | the key the view registry assigns a view over that object: a `listViews` / `formViews` map key, or the default `list`'s `name` — `default` when it has none (see [ObjectUI Integration](#objectui-integration)) | | `objects.{object}._sections.{section}` | a `fieldGroups[].key`, a named section of a form view over that object (a `formViews` entry or the default `form`), or a named section of a `record:details` component on a page bound to it | | `objects.{object}._tabs.{tab}` | a filter-preset tab's `name` in `interfaceConfig.userFilters.tabs` on a page over that object (`interfaceConfig.source`, else the page's `object`) — a list view's own `tabs` has no renderer and is not resolvable | +| `objects.{object}._relatedLists.{list}` | the `list` of an object-form `relatedLists` entry on that object that authors a `label` — a dotted `object.field` is one key; a key over an entry with no `label`, a bare-string entry or a built-in tab is an orphan, because that tab's title is the child lookup field's `relatedListTitle`, translated on the child | | `objects.{object}._validations.{rule}` | a validation rule's `name` in that object's `validations[]` or in an `objectExtensions[]` entry aimed at it — a `conditional` rule's `then` / `otherwise` branch included | | `objects.{object}._actions.{action}` | an action bound to that object: one in its `actions`, or a stack-level action whose `objectName` is that object | | `globalActions.{action}` | an action with **no** `objectName` — a key naming a bound action is an error whose message names the `objects.{owner}._actions.{action}` key to write instead, `{owner}` being the action's own `objectName` | diff --git a/content/docs/references/system/translation.mdx b/content/docs/references/system/translation.mdx index e6ae24a7478..57be1501aab 100644 --- a/content/docs/references/system/translation.mdx +++ b/content/docs/references/system/translation.mdx @@ -98,6 +98,7 @@ Translation data for a single object | **_actions** | `Record` | optional | Action translations keyed by action name | | **_sections** | `Record }>` | optional | Section translations keyed by section name | | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | +| **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | ### Nested Shape: `ObjectTranslationData.fields[string]` @@ -156,6 +157,12 @@ Translation data for a single field | :--- | :--- | :--- | :--- | | **label** | `string` | optional | Translated tab label | +### Nested Shape: `ObjectTranslationData._relatedLists[string]` + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **label** | `string` | optional | Translated related list title (overlays the relatedLists entry's own `label`) | + ### Nested Shape: `ObjectTranslationData._validations[string]` | Property | Type | Required | Description | @@ -215,6 +222,7 @@ Translation data for a single object | **_actions** | `Record` | optional | Action translations keyed by action name | | **_sections** | `Record }>` | optional | Section translations keyed by section name | | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | +| **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | ### Nested Shape: `PlatformTranslationData.picklists[string]` @@ -405,6 +413,7 @@ Translation data for a single object | **_actions** | `Record` | optional | Action translations keyed by action name | | **_sections** | `Record }>` | optional | Section translations keyed by section name | | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | +| **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | ### Nested Shape: `ServedTranslationData.picklists[string]` @@ -658,6 +667,7 @@ Translation data for a single object | **_actions** | `Record` | optional | Action translations keyed by action name | | **_sections** | `Record }>` | optional | Section translations keyed by section name | | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | +| **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | ### Nested Shape: `TranslationData.picklists[string]` @@ -880,6 +890,7 @@ Translation data for a single object | **_actions** | `Record` | optional | Action translations keyed by action name | | **_sections** | `Record }>` | optional | Section translations keyed by section name | | **_tabs** | `Record` | optional | Filter-preset tab translations keyed by tab name | +| **_relatedLists** | `Record` | optional | Record-page related list titles keyed by the relatedLists entry list name | | **_validations** | `Record` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) | ### Nested Shape: `TranslationItem.picklists[string]` diff --git a/docs/audits/2026-07-unknown-key-strictness-ledger.counts/system.md b/docs/audits/2026-07-unknown-key-strictness-ledger.counts/system.md index e669c99724b..e35ee35f184 100644 --- a/docs/audits/2026-07-unknown-key-strictness-ledger.counts/system.md +++ b/docs/audits/2026-07-unknown-key-strictness-ledger.counts/system.md @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate. | Dir | Sites | |---|---| -| `system/` | 408 | +| `system/` | 409 | diff --git a/packages/lint/src/i18n-related-lists-label-36528.test.ts b/packages/lint/src/i18n-related-lists-label-36528.test.ts new file mode 100644 index 00000000000..d0cf80457d2 --- /dev/null +++ b/packages/lint/src/i18n-related-lists-label-36528.test.ts @@ -0,0 +1,144 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// `objects.._relatedLists..label` on the two lint readers every +// object translation group has: the extractor walk that scaffolds and gates +// the key, and the orphan rule that refuses a key nothing reads. Both read the +// same fact the resolver does: an object-form `relatedLists` entry on the +// parent that AUTHORS a `label`, keyed by its literal `list`. + +import { describe, it, expect } from 'vitest'; +import { collectExpectedEntries } from './i18n-walk.js'; +import { validateTranslationReferences, TRANSLATION_TARGET_UNKNOWN } from './validate-translation-references.js'; + +const ACCOUNT = { + name: 'account', + label: 'Account', + fields: { name: { name: 'name', type: 'text', label: 'Name' } }, + relatedLists: [ + { list: 'contact', label: 'People' }, + { list: 'event.related_to', label: 'Meetings' }, + { list: 'opportunity' }, + 'case', + 'sys_activity', + ], +}; + +describe('collectExpectedEntries — a relatedLists entry\'s label', () => { + const entries = collectExpectedEntries({ objects: [ACCOUNT] }, { warnedGroups: new Set() }); + const relatedListEntries = entries.filter((e) => e.path[2] === '_relatedLists'); + + it('emits the key for each labelled object entry, a dotted list as one key, seeded from the label', () => { + expect(relatedListEntries.map((e) => [e.path, e.sourceValue, e.inline])).toEqual([ + [['objects', 'account', '_relatedLists', 'contact', 'label'], 'People', 'People'], + [['objects', 'account', '_relatedLists', 'event.related_to', 'label'], 'Meetings', 'Meetings'], + ]); + expect(relatedListEntries.every((e) => e.source === 'object' && e.objectName === 'account')).toBe(true); + }); + + it('emits nothing for an entry with no label, a bare name or a built-in tab', () => { + const lists = relatedListEntries.map((e) => e.path[3]); + expect(lists).not.toContain('opportunity'); + expect(lists).not.toContain('case'); + expect(lists).not.toContain('sys_activity'); + }); +}); + +describe('validateTranslationReferences — _relatedLists', () => { + const stackWith = (relatedLists: Record) => ({ + objects: [ACCOUNT], + translations: [{ 'zh-CN': { objects: { account: { _relatedLists: relatedLists } } } }], + }); + + it('resolves a key over each labelled entry, the dotted one included', () => { + expect(validateTranslationReferences(stackWith({ + contact: { label: '联系人' }, + 'event.related_to': { label: '会议' }, + }))).toEqual([]); + }); + + it('flags a key naming no entry, and one over an entry that carries no label', () => { + const findings = validateTranslationReferences(stackWith({ + contacts: { label: '联系人' }, + opportunity: { label: '商机' }, + case: { label: '工单' }, + })); + expect(findings.map((f) => [f.rule, f.severity, f.path])).toEqual([ + [TRANSLATION_TARGET_UNKNOWN, 'error', 'translations[0]["zh-CN"].objects.account._relatedLists.contacts'], + [TRANSLATION_TARGET_UNKNOWN, 'error', 'translations[0]["zh-CN"].objects.account._relatedLists.opportunity'], + [TRANSLATION_TARGET_UNKNOWN, 'error', 'translations[0]["zh-CN"].objects.account._relatedLists.case'], + ]); + // A misspelt list is pointed at the labelled one it nearly names. + expect(findings[0].message).toContain('"contact"'); + for (const f of findings) { + expect(f.message.length, f.message).toBeLessThanOrEqual(200); + expect(f.hint.length, f.hint).toBeLessThanOrEqual(200); + } + }); + + it('resolves a key over a labelled entry an extension brings: a `.custom` arrangement or a list placement', () => { + const translations = [{ 'zh-CN': { objects: { account: { _relatedLists: { quote: { label: '报价' } } } } } }]; + const arrangement = { + objects: [ACCOUNT], + objectExtensions: [{ extend: 'account', relatedLists: [{ list: 'quote', label: 'Quotes' }, 'contact'] }], + translations, + }; + expect(validateTranslationReferences(arrangement)).toEqual([]); + const placement = { + objects: [ACCOUNT], + objectExtensions: [{ extend: 'account', place: [{ list: 'quote', after: 'contact', label: 'Quotes' }] }], + translations, + }; + expect(validateTranslationReferences(placement)).toEqual([]); + // Control: the same extension entry with no label titles nothing. + const unlabelled = { + objects: [ACCOUNT], + objectExtensions: [{ extend: 'account', place: [{ list: 'quote', after: 'contact' }] }], + translations, + }; + expect(validateTranslationReferences(unlabelled).map((f) => f.path)) + .toEqual(['translations[0]["zh-CN"].objects.account._relatedLists.quote']); + }); + + it('names a built-in tab as such, listed or not: no form, no child field to point at', () => { + const findings = validateTranslationReferences(stackWith({ + sys_activity: { label: '动态' }, + sys_attachment: { label: '附件' }, + })); + expect(findings.map((f) => f.path)).toEqual([ + 'translations[0]["zh-CN"].objects.account._relatedLists.sys_activity', + 'translations[0]["zh-CN"].objects.account._relatedLists.sys_attachment', + ]); + for (const f of findings) { + expect(f.message).toContain('built-in record-page tab'); + expect(f.hint).not.toContain('relatedListTitle'); + expect(f.hint).not.toContain('{ list, label }'); + expect(f.hint.length, f.hint).toBeLessThanOrEqual(200); + } + }); + + it('does not count a `.custom` entry with `hidden: true` as labelled', () => { + const translations = [{ 'zh-CN': { objects: { account: { _relatedLists: { quote: { label: '报价' } } } } } }]; + const findings = validateTranslationReferences({ + objects: [ACCOUNT], + objectExtensions: [{ extend: 'account', relatedLists: [{ list: 'quote', label: 'Quotes', hidden: true }, 'contact'] }], + translations, + }); + expect(findings.map((f) => f.path)).toEqual(['translations[0]["zh-CN"].objects.account._relatedLists.quote']); + expect(findings[0].message).toContain('hidden'); + expect(findings[0].message.length).toBeLessThanOrEqual(200); + }); + + it('brackets a dotted list in the finding path, as the locale segment is', () => { + const findings = validateTranslationReferences(stackWith({ 'event.owner_id': { label: '会议' } })); + expect(findings.map((f) => f.path)) + .toEqual(['translations[0]["zh-CN"].objects.account._relatedLists["event.owner_id"]']); + }); + + it('flags every key on an object that declares no relatedLists', () => { + const findings = validateTranslationReferences({ + objects: [{ ...ACCOUNT, relatedLists: undefined }], + translations: [{ 'zh-CN': { objects: { account: { _relatedLists: { contact: { label: '联系人' } } } } } }], + }); + expect(findings.map((f) => f.path)).toEqual(['translations[0]["zh-CN"].objects.account._relatedLists.contact']); + }); +}); diff --git a/packages/lint/src/i18n-walk.ts b/packages/lint/src/i18n-walk.ts index f25862a2074..82dec193ac4 100644 --- a/packages/lint/src/i18n-walk.ts +++ b/packages/lint/src/i18n-walk.ts @@ -85,6 +85,8 @@ * ^ a bulk param spells its hint `help`; an ACTION param spells the same * idea `helpText` (`ui/bulk-action.zod.ts`'s known divergence) * objects.._validations..message + * objects.._relatedLists..label (an object-form `relatedLists` + * entry that authors a `label`) * objects.._actions..label * objects.._actions..description * objects.._actions..confirmText @@ -998,6 +1000,28 @@ function pushValidationMessages( } } +/** + * Emit `objects.._relatedLists..label` for every object-form + * `relatedLists` entry of an object that authors a `label` (the record page's + * tab title and table heading for that list, which wins over the child FK's + * `relatedListTitle`). The key is the entry's literal `list`, a dotted + * `object.field` included, indexed as is. Only an AUTHORED label is emitted: + * `translateObject` translates that label and swaps nothing in for an entry + * that has none, so a key for one would ask a translator for a string no + * screen shows. + */ +function pushRelatedListLabels(out: ExpectedEntry[], objectName: string, entries: unknown): void { + if (!Array.isArray(entries)) return; + for (const entry of entries) { + if (!entry || typeof entry !== 'object' || Array.isArray(entry)) continue; + const list = (entry as any).list; + if (typeof list !== 'string' || list.length === 0) continue; + const label = (entry as any).label; + if (typeof label !== 'string' || label.length === 0) continue; + pushEntry(out, ['objects', objectName, '_relatedLists', list, 'label'], label, 'object', { objectName }); + } +} + // ─── Object sections (`objects.._sections.
.label`) ───────── // // A section heading is authored in TWO independent places and rendered from @@ -1626,6 +1650,14 @@ export function collectExpectedEntries( // Custom validation-rule rejection messages (`_validations..message`). pushValidationMessages(out, objectName, obj.validations, 0); + + // Record-page related-list titles (`_relatedLists..label`): the + // `label` an object-form `relatedLists` entry authors on this parent, + // keyed by the entry's literal `list` (`object.field` is one key). + // `translateObject` overlays only an authored label, so an entry without + // one — and a bare-string entry or built-in tab — gets no key: its title + // is the child FK's `relatedListTitle`, keyed on the child above. + pushRelatedListLabels(out, objectName, obj.relatedLists); } // ── Top-level views ────────────────────────────────────────────── diff --git a/packages/lint/src/object-graph.ts b/packages/lint/src/object-graph.ts index 0ff71210f1b..58b26d5577b 100644 --- a/packages/lint/src/object-graph.ts +++ b/packages/lint/src/object-graph.ts @@ -406,6 +406,18 @@ export interface VisibleObjectExtension { * (`os validate` refuses any other writer), not this fold's. */ fieldGroups: AnyRec[]; + /** + * The record entries of its `relatedLists` (the `.custom` arrangement, + * ADR-0146 D10; a bare name carries no title and is left out) and of its + * `place` (`[]` when none). The ones naming a `list` are the child-list + * entries the extension brings onto the target's record-page tabs, each with + * its optional `label`; a field or group placement names none and is + * skipped by the reader. Carried for the + * one reader that addresses a tab title by list name + * (`validate-translation-references.ts`, `_relatedLists.LIST`); like + * `validations`, carrying them changes nothing about which entries survive. + */ + relatedListEntries: AnyRec[]; /** * [#33494] Set on an entry the host's registry already holds * ({@link StoredObjectExtension}), folded in at its priority but never @@ -494,6 +506,10 @@ export function objectExtensionsByTarget( fields: recordsOf(ext.fields), validations: recordsOf(ext.validations), fieldGroups: Array.isArray(ext.fieldGroups) ? ext.fieldGroups.filter(isRec) : [], + relatedListEntries: [ + ...(Array.isArray(ext.relatedLists) ? ext.relatedLists : []), + ...(Array.isArray(ext.place) ? ext.place : []), + ].filter(isRec), label: ext.label, fieldPatches: isRec(ext.fieldPatches) ? Object.fromEntries( diff --git a/packages/lint/src/validate-security-posture.test.ts b/packages/lint/src/validate-security-posture.test.ts index 6ab6729c4e4..6b9243b9819 100644 --- a/packages/lint/src/validate-security-posture.test.ts +++ b/packages/lint/src/validate-security-posture.test.ts @@ -2394,8 +2394,10 @@ const READ_SURFACES: Array<{ receiver: string; expected: string[]; declaredBy: s { receiver: 'ext', // `fieldGroups` [ADR-0146 D10]: carried by the shared extension fold for - // the translation rule's `_sections` anchors; this rule reads none of it. - expected: ['extend', 'fieldGroups', 'fieldPatches', 'fields', 'label', 'priority', 'validations'], + // the translation rule's `_sections` anchors; `place` and `relatedLists` + // likewise, for its `_relatedLists` anchors (the tab entries an extension + // brings). This rule reads none of them. + expected: ['extend', 'fieldGroups', 'fieldPatches', 'fields', 'label', 'place', 'priority', 'relatedLists', 'validations'], declaredBy: 'ObjectStackSchema.objectExtensions[]', keys: () => shapeKeysOf(ObjectStackSchema.shape.objectExtensions), }, diff --git a/packages/lint/src/validate-translation-references.test.ts b/packages/lint/src/validate-translation-references.test.ts index eedb9271964..2c14fb15da8 100644 --- a/packages/lint/src/validate-translation-references.test.ts +++ b/packages/lint/src/validate-translation-references.test.ts @@ -3891,6 +3891,11 @@ describe('validateTranslationReferences — object-branch coverage vs the schema ghost: { _tabs: { ghost_tab: { label: 'Ghost' } } }, path: 'translations[0].en.objects.crm_lead._tabs.ghost_tab', }, + _relatedLists: { + kind: 'reference-checked', + ghost: { _relatedLists: { ghost_list: { label: 'Ghost' } } }, + path: 'translations[0].en.objects.crm_lead._relatedLists.ghost_list', + }, _validations: { kind: 'reference-checked', ghost: { _validations: { ghost_rule: { message: 'Ghost' } } }, diff --git a/packages/lint/src/validate-translation-references.ts b/packages/lint/src/validate-translation-references.ts index c18b360a22f..1b96ed3452f 100644 --- a/packages/lint/src/validate-translation-references.ts +++ b/packages/lint/src/validate-translation-references.ts @@ -276,6 +276,7 @@ import { pageTabItemKey, walkAddressedPageComponents, } from '@objectstack/spec/system'; +import { isRecordPageBuiltinTab, relatedListEntryHidden } from '@objectstack/spec/data'; import { walkFlowNodes } from './flow-walk.js'; import { objectExtensionsByTarget, packagesOf, recordsOf, suggestName } from './object-graph.js'; import { walkPageComponents } from './page-walk.js'; @@ -482,6 +483,24 @@ interface ObjectFacts { * for why that is the only carrier and how the object binding is resolved. */ tabs: Set; + /** + * `_relatedLists` names — the `list` of every object-form `relatedLists` + * entry this object declares WITH a `label`, the only entries + * `translateObject` overlays `objects.._relatedLists..label` onto. + */ + relatedListLabels: Set; + /** + * Every list this object's `relatedLists` names, labelled or not (a bare + * string, an object entry, a built-in tab) — read only to say WHY a + * `_relatedLists` key over a named but unlabelled entry resolves nothing. + */ + relatedListNames: Set; + /** + * The lists a paired `.custom` arrangement hides (`{ list, hidden: true }`, + * ADR-0146 D10): no tab shows them, so their title is read nowhere — read + * only to say so. + */ + relatedListHidden: Set; } /** Everything a `flows..screens.` key may legally name. */ @@ -642,6 +661,9 @@ function emptyFacts(): ObjectFacts { sectionEntries: new Map(), validations: new Set(), tabs: new Set(), + relatedListLabels: new Set(), + relatedListNames: new Set(), + relatedListHidden: new Set(), }; } @@ -1123,18 +1145,24 @@ function contributedNavItemsByApp(stack: AnyRec): Map { * its declared keys: `extend`, `priority`, `fields`, `validations`, `indexes`, * `label`, `pluralLabel`, `description`, and the arrangement keys the base's * paired `.custom` package writes, `fieldGroups` and `relatedLists` - * (ADR-0146 D10). Everything else is refused BY NAME at the extension level + * (ADR-0146 D10), and `place`, which positions the items the extension brings. + * Everything else is refused BY NAME at the extension level * with authoring guidance (`actions`, `listViews`, `hooks` carry their own * `guidance` text; `views`, `sections` and `tabs` fall to the shared * unknown-key refusal). Measured against the schema rather than read off the * merge: each of those six produced an extension-level `unrecognized_keys` * issue, while `fields`, `validations` and `fieldGroups` parsed. * - * ⇒ THREE of this rule's rungs are reachable through an extension: - * `objects..fields.*`, `objects.._validations.*`, and + * ⇒ FOUR of this rule's rungs are reachable through an extension: + * `objects..fields.*`, `objects.._validations.*`, * `objects.._sections.*` for the groups a `.custom` arrangement brings - * (`fieldGroups[].key` is the section anchor, ADR-0085). `indexes` and - * `relatedLists` are not translatable here; `label` / `pluralLabel` / + * (`fieldGroups[].key` is the section anchor, ADR-0085), and + * `objects.._relatedLists.*` for a labelled tab entry it brings: an + * object-form entry of a `.custom` arrangement's `relatedLists` that is not + * `hidden`, or a list placement in `place` (spliced, where the target declares + * `relatedLists`, into the served target and into the packaged base the read + * compares with, `getPackagedObjectBase`), each titling a tab of + * the served target by its `list`. `indexes` is not translatable; `label` / `pluralLabel` / * `description` are leaf copy on an object that already resolved, and this * rule checks no leaf. ⛔ Do not grow this fold to `_views` / `_tabs` / * `_actions` "for symmetry": an extension cannot contribute any of them, so a @@ -1303,6 +1331,16 @@ function buildUniverse(stack: AnyRec): Universe { for (const rule of recordsOf(obj.validations)) { collectValidationRuleNames(rule, facts.validations); } + // `_relatedLists.` is keyed by an object-form `relatedLists` entry's + // literal `list` (`object.field` is one key), and resolves only over an + // entry that authors a `label`: `translateObject` overlays that label and + // swaps nothing in for an entry without one. + for (const entry of Array.isArray(obj.relatedLists) ? obj.relatedLists : []) { + const list = typeof entry === 'string' ? entry : isRec(entry) ? strName(entry.list) : undefined; + if (!list) continue; + facts.relatedListNames.add(list); + if (isRec(entry) && typeof entry.label === 'string' && entry.label.length > 0) facts.relatedListLabels.add(list); + } }; for (const obj of recordsOf(stack.objects)) { @@ -1379,6 +1417,26 @@ function buildUniverse(stack: AnyRec): Universe { const key = strName(group.key); if (key) facts.sections.add(key); } + // `_relatedLists.` is keyed by a labelled entry's `list`: a + // `.custom` arrangement's `relatedLists` entry (ADR-0146 D10) and a + // list placement's `place` entry each title a tab of the target, and + // where the target declares `relatedLists` the served target carries + // that entry, which `translateObject` translates as it does the + // target's own (a placed entry is part of the packaged base it is + // compared with, `getPackagedObjectBase`). A placement on a target + // that declares none is not applied, and its key is accepted here all + // the same: this fold does not read whether the target declares the + // list. An arrangement entry with `hidden: true` titles no tab. + for (const entry of extension.relatedListEntries) { + const list = strName(entry.list); + if (!list) continue; + facts.relatedListNames.add(list); + if (relatedListEntryHidden(entry)) { + facts.relatedListHidden.add(list); + continue; + } + if (typeof entry.label === 'string' && entry.label.length > 0) facts.relatedListLabels.add(list); + } } } @@ -2073,6 +2131,48 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind ); } + // _relatedLists. + // + // A record-page related-list title the parent declares on an + // object-form `relatedLists` entry. A key over a list the object names + // without a `label` translates nothing: that tab's title is the child + // FK's `relatedListTitle`, keyed on the child. + for (const listName of Object.keys(asRecord(rawNode._relatedLists))) { + if (facts.relatedListLabels.has(listName)) continue; + const listWhere = `${inLocale} · object "${objectName}" · related list "${listName}"`; + const listPath = `${objPath}._relatedLists${memberPath(listName)}`; + if (isRecordPageBuiltinTab(listName)) { + orphan(listWhere, listPath, + `"${listName}" is a built-in record-page tab, written only bare and titled by the platform, ` + + `so no title of object "${objectName}" reads this key.`, + `Drop this key: a built-in tab takes no \`label\` here.`); + continue; + } + if (facts.relatedListHidden.has(listName)) { + orphan(listWhere, listPath, + `Related list "${listName}" of object "${objectName}" is hidden by the \`.custom\` ` + + `arrangement (\`hidden: true\`), so no tab shows a title from this key.`, + `Drop this key, or show the tab (drop \`hidden\`) and give the entry a \`label\`.`); + continue; + } + const named = facts.relatedListNames.has(listName); + orphan( + listWhere, + listPath, + named + ? `Related list "${listName}" of object "${objectName}" carries no \`label\` in ` + + `\`relatedLists\`, so no title reads this key.` + : `Translations are keyed to related list "${listName}", which no \`relatedLists\` entry ` + + `of object "${objectName}" names, so nothing reads this key.` + + suggest(listName, facts.relatedListLabels), + named + ? `Give the entry a \`label\` ({ list, label }) to title it here, or translate the ` + + `child lookup field's \`relatedListTitle\` instead, and drop this key.` + : `Match the key to the entry's \`list\` (a dotted object.field is one key), or drop ` + + `it if the entry was renamed or removed.`, + ); + } + // _validations. // // Same shape as `_tabs` above: a machine name that either exists on diff --git a/packages/metadata-protocol/src/protocol-translated-echo.related-lists-36528.test.ts b/packages/metadata-protocol/src/protocol-translated-echo.related-lists-36528.test.ts new file mode 100644 index 00000000000..e974cca918b --- /dev/null +++ b/packages/metadata-protocol/src/protocol-translated-echo.related-lists-36528.test.ts @@ -0,0 +1,53 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// The save door's translated-echo restore on a `relatedLists` entry's +// `label`: the `/meta` read overlays `objects.._relatedLists..label` +// onto it, Studio saves the whole body it read, and the translation must not +// become the stored title. + +import { describe, it, expect } from 'vitest'; +import { translateObject, type TranslationBundle } from '@objectstack/spec/system'; +import { restoreTranslatedEchoes, translatedEchoNotices } from './protocol-translated-echo.js'; + +const bundle: TranslationBundle = { + 'zh-CN': { objects: { account: { _relatedLists: { contact: { label: '联系人' }, 'event.related_to': { label: '会议' } } } } }, +}; + +const stored = () => ({ + name: 'account', + label: 'Account', + fields: {}, + relatedLists: [{ list: 'contact', label: 'People' }, { list: 'event.related_to', label: 'Meetings' }, 'case'], +}); + +describe('restoreTranslatedEchoes — a relatedLists entry\'s label', () => { + it('puts a translated entry label back to its source, the dotted list included, and names each slot', () => { + const echo = translateObject(stored(), bundle, { locale: 'zh-CN' }); + // The read did translate it: the case is real, not a no-op. + expect((echo.relatedLists[0] as { label: string }).label).toBe('联系人'); + const { item, restored } = restoreTranslatedEchoes(echo, { source: stored(), bundle }); + expect((item as ReturnType).relatedLists).toEqual(stored().relatedLists); + expect(restored).toEqual([ + { path: 'relatedLists[contact].label', from: '联系人', to: 'People' }, + { path: 'relatedLists[event.related_to].label', from: '会议', to: 'Meetings' }, + ]); + expect(translatedEchoNotices('account', restored)[0].path).toBe('objects.account.relatedLists[contact].label'); + }); + + it('keeps a label the author typed that is no translation of its source', () => { + const body = stored(); + body.relatedLists[0] = { list: 'contact', label: 'Key People' }; + const { item, restored } = restoreTranslatedEchoes(body, { source: stored(), bundle }); + expect(item).toBe(body); + expect(restored).toEqual([]); + }); + + it('keeps a label on an entry the source does not title', () => { + const source = stored(); + source.relatedLists[0] = { list: 'contact' } as never; + const body = stored(); + body.relatedLists[0] = { list: 'contact', label: '联系人' }; + const { item } = restoreTranslatedEchoes(body, { source, bundle }); + expect(item).toBe(body); + }); +}); diff --git a/packages/metadata-protocol/src/protocol-translated-echo.ts b/packages/metadata-protocol/src/protocol-translated-echo.ts index 196e74e73b4..98f51ab0c07 100644 --- a/packages/metadata-protocol/src/protocol-translated-echo.ts +++ b/packages/metadata-protocol/src/protocol-translated-echo.ts @@ -63,6 +63,10 @@ * edit and is kept, and a field the source does not declare has nothing to * be compared with. * + * The slots are the ones the read translates: the object's scalars, each + * field's text slots and option labels, and the `label` of each object-form + * `relatedLists` entry (matched to its source entry by `list`). + * * The source is translated with the read's own options, the packaged base * included: a slot the read serves untranslated (an overlay that diverged * from the packaged text) is no translation's source. @@ -166,6 +170,17 @@ function optionLabel(options: unknown, key: string): unknown { return optionOf(options, key)?.label; } +/** The object-form `relatedLists` entry naming `list`, the first one. */ +function relatedListEntry(entries: unknown, list: string): Rec | undefined { + return Array.isArray(entries) ? (entries.find((e) => isRec(e) && e.list === list) as Rec | undefined) : undefined; +} + +/** That entry's `label`; {@link NOT_DECLARED} when no entry names `list` with a string label. */ +function relatedListLabel(entries: unknown, list: string): unknown { + const label = relatedListEntry(entries, list)?.label; + return typeof label === 'string' ? label : NOT_DECLARED; +} + /** * The locales a read could have translated into: the bundle's own, then the * built-in system-field table's. Order is irrelevant to the verdict. @@ -285,6 +300,9 @@ export function restoreTranslatedEchoes( for (const slot of OBJECT_TEXT_SLOTS) { if (typeof args.source[slot] === 'string') storedDoc[slot] = args.source[slot]; } + // The parent's `relatedLists`: the read translates an object-form + // entry's `label` (`objects.NAME._relatedLists.LIST.label`). + if (Array.isArray(args.source.relatedLists)) storedDoc.relatedLists = args.source.relatedLists; } const injectedDoc: Rec = { name: item.name, fields: {} }; for (const [name, def] of Object.entries(injectedSystemColumnDefs(item))) { @@ -364,6 +382,30 @@ export function restoreTranslatedEchoes( nextItem[slot] = hit.to; } + // A `relatedLists` entry's `label`, by the entry's `list`: the read + // overlays `objects.NAME._relatedLists.LIST.label` onto it, so a save + // carrying that translation back stores the source title instead. + if (Array.isArray(item.relatedLists)) { + let entries: unknown[] | undefined; + item.relatedLists.forEach((entry, index) => { + if (!isRec(entry) || typeof entry.list !== 'string' || typeof entry.label !== 'string') return; + const list = entry.list; + const hit = sourceOf( + entry.label, + (doc) => relatedListLabel(doc.relatedLists, list), + () => ({ base: relatedListEntry(isRec(args.packagedBase) ? args.packagedBase.relatedLists : undefined, list), key: 'label' }), + ); + if (!hit || typeof hit.to !== 'string') return; + restored.push({ path: `relatedLists[${list}].label`, from: entry.label, to: hit.to }); + entries ??= [...(item.relatedLists as unknown[])]; + entries[index] = { ...entry, label: hit.to }; + }); + if (entries) { + nextItem = nextItem === item ? { ...item } : nextItem; + nextItem.relatedLists = entries; + } + } + const nextFields = new Map(); for (const [name, field] of incoming) { if (!sources.some((source) => source.fields.has(name))) continue; diff --git a/packages/objectql/src/registry-platform-global.ts b/packages/objectql/src/registry-platform-global.ts index a27d15c85ba..b7a7d23c872 100644 --- a/packages/objectql/src/registry-platform-global.ts +++ b/packages/objectql/src/registry-platform-global.ts @@ -47,6 +47,7 @@ import { TENANT_SCOPE_FIELD_DEF, isCodeArtifactBody } from '@objectstack/metadat import { DEFAULT_EXTENDER_PRIORITY, applyFieldPatches, ownFieldNamesOf, packagedAddedFields, stableStringify, withoutField } from './registry-top-level.js'; import type { ObjectContributor, ObjectExtensionBody, ObjectExtensionFoldOptions } from './registry-top-level.js'; import { TENANT_SCOPE_INDEX, extendContributionRefusal, provisionTenantScopeIndex } from './registry.js'; +import { applyExtensionPlacements, fieldGroupKeysOf, placementContributorsOf } from './registry-extension-placement.js'; import type { SchemaRegistry } from './registry.js'; /** @@ -520,7 +521,7 @@ export class PlatformGlobalFacet { } /** The body of `SchemaRegistry#getPackagedObjectBase`; the method's docblock there is its contract. */ - static getPackagedObjectBase(this: Pick, name: string): ServiceObject | undefined { + static getPackagedObjectBase(this: Pick, name: string): ServiceObject | undefined { const owner = this.getPackagedObjectOwner(name); if (!owner) return undefined; const fqn = this.resolveObjectKey(name); @@ -536,13 +537,27 @@ export class PlatformGlobalFacet { owner.definition, contributors.filter((c) => !(c.ownership === 'extend' && this.isPackageDisabled(c.packageId))), ); - if (!extended && addedFields === undefined) return owner.definition; + // [#36528] The record-page tabs a code extender's list placement (`place`) + // splices into the owner's `relatedLists`, as the fold splices them, with + // the same filter as the added fields; only the lists pass is read off. + const placedLists = packagedPlacedRelatedLists( + owner.definition, + contributors.filter((c) => c.ownership === 'extend' && isCodeArtifactBody(c.definition) && !this.isPackageDisabled(c.packageId)), + (child) => { + const childKey = this.resolveObjectKey(child); + const childOwner = childKey === undefined ? undefined : this.getObjectOwner(childKey); + if (childOwner === undefined) return undefined; + return childOwner.packageId ?? null; + }, + ); + if (!extended && addedFields === undefined && placedLists === undefined) return owner.definition; return { ...owner.definition, ...(extended ? { validations: (this.packagedRules(contributors) ?? []) as ServiceObject['validations'] } : {}), ...(addedFields !== undefined ? { fields: { ...owner.definition.fields, ...addedFields } as ServiceObject['fields'] } : {}), + ...(placedLists !== undefined ? { relatedLists: placedLists as ServiceObject['relatedLists'] } : {}), }; } @@ -795,3 +810,37 @@ export class PlatformGlobalFacet { return true; } } + +/** + * [#36528] The owner's `relatedLists` with the list placements (`place`) of + * `extenders` spliced in by the fold's own pass ({@link applyExtensionPlacements}), + * or `undefined` when none applies — an owner that declares no `relatedLists` + * (`PLACEMENT_ARRANGES_DECLARED_ONLY`), or no extender places a list. Only the + * lists pass is read off: the groups and fields the same call arranges stay + * the owner's in the packaged base, and its notes are the fold's to name. + * + * Why the packaged base carries them (`SchemaRegistry#getPackagedObjectBase`): + * the sentence that holds for a field a code extender adds holds for a + * record-page tab it places (`place: [{ list, label? }]`). The catalog row + * for the placed title (`_relatedLists..label`) can only translate what + * that extender ships; read off the owner alone, the placed title counted as + * authored after the fact and `/meta` served it untranslated. A paired + * `.custom` arrangement (ADR-0146 D10) is the customization layer and is + * never folded in: its titles diverge and read the pair's own translations. + */ +function packagedPlacedRelatedLists( + owner: ServiceObject, + extenders: readonly ObjectContributor[], + childPackageOf: (child: string) => string | null | undefined, +): unknown[] | undefined { + const placing = placementContributorsOf(extenders, ownFieldNamesOf(owner)); + if (placing.length === 0) return undefined; + const placed = applyExtensionPlacements(owner, placing, { + objectName: String(owner.name ?? ''), + ownerGroupKeys: fieldGroupKeysOf(owner), + childPackageOf, + }); + const before = (owner as { relatedLists?: unknown }).relatedLists; + const after = (placed.object as { relatedLists?: unknown }).relatedLists; + return after !== before && Array.isArray(after) ? after : undefined; +} diff --git a/packages/objectql/src/registry-related-lists-label-translation-36528.test.ts b/packages/objectql/src/registry-related-lists-label-translation-36528.test.ts new file mode 100644 index 00000000000..52f047c7572 --- /dev/null +++ b/packages/objectql/src/registry-related-lists-label-translation-36528.test.ts @@ -0,0 +1,127 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * `objects.._relatedLists..label` reaches the titles an + * extension brings, read through the `/meta` read's real options: the SERVED + * object (the registry fold has spliced an extension's list placement and the + * paired `.custom` package's arrangement into `relatedLists`) translated + * against the packaged base the REST read hands `translateMetadataDocument` + * (`packagedObjectBaseOf(protocol, 'object', name)` in `@objectstack/rest`, + * which asks `ObjectStackProtocolImplementation#getPackagedObjectBase`, which + * asks the engine's registry). A code extender's placed entry is part of that + * base (#36528), so its title reads the deployment catalog; a `.custom` title + * diverges from the base and reads the pair's translations (`pairBundle`). + */ + +import { describe, it, expect } from 'vitest'; +import { translateMetadataDocument, type TranslationBundle } from '@objectstack/spec/system'; +import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; +import { ObjectQL } from './index.js'; +import type { SchemaRegistry } from './registry.js'; + +const BASE = 'com.vendor.crm'; +const PAIR = 'com.vendor.crm.custom'; +const EXT = 'com.acme.tax'; +const OBJ = 'crm_lead'; + +const child = (name: string, label: string) => ({ + name, + label, + fields: { lead_id: { name: 'lead_id', type: 'lookup', label: 'Lead', reference: OBJ } }, +}); + +/** The engine's registry, and the protocol the REST read asks for the packaged base. */ +let protocol: ObjectStackProtocolImplementation; + +function withBase(): SchemaRegistry { + const engine = new ObjectQL(); + protocol = new ObjectStackProtocolImplementation(engine as never); + const reg = engine.registry; + reg.logLevel = 'silent'; + reg.registerObject({ + name: OBJ, + label: 'Lead', + fields: { name: { name: 'name', type: 'text', label: 'Name' } }, + relatedLists: [{ list: 'crm_task', label: 'Tasks' }, 'crm_note'], + } as never, BASE, undefined, 'own'); + for (const [name, label] of [['crm_task', 'Task'], ['crm_note', 'Note']]) { + reg.registerObject(child(name, label) as never, BASE, undefined, 'own'); + } + return reg; +} + +const BUNDLE: TranslationBundle = { + 'zh-CN': { + objects: { + crm_lead: { + _relatedLists: { + crm_task: { label: '任务' }, + crm_note: { label: '备注' }, + acme_audit: { label: '审计' }, + }, + }, + }, + }, +}; + +/** The pair's own translations: what `pairTranslationBundleOf` hands the read for the `.custom` text. */ +const PAIR_BUNDLE: TranslationBundle = { + 'zh-CN': { objects: { crm_lead: { _relatedLists: { crm_note: { label: '笔记' } } } } }, +}; + +/** The `/meta` object read's translation, with the options `meta-item-read-gate` builds. */ +const read = (served: unknown, packagedBase: unknown, pairBundle?: TranslationBundle) => + translateMetadataDocument('object', served as never, BUNDLE, { + locale: 'zh-CN', + packagedBase, + ...(pairBundle !== undefined ? { pairBundle } : {}), + } as never); + +/** `packagedObjectBaseOf(protocol, 'object', OBJ)`: the object accessor of the REST read. */ +const packagedBaseOf = (name: string) => protocol.getPackagedObjectBase(name); + +const titles = (body: unknown) => + ((body as { relatedLists: unknown[] }).relatedLists).map((e) => (typeof e === 'string' ? e : (e as { label?: string }).label)); + +describe('_relatedLists over the served (folded) parent', () => { + it('translates the title an extension package\'s list placement brings, beside the owner\'s', () => { + const reg = withBase(); + reg.registerObject(child('acme_audit', 'Audit') as never, EXT, undefined, 'own'); + reg.registerObject( + { name: OBJ, place: [{ list: 'acme_audit', after: 'crm_task', label: 'Audit trail' }] } as never, + EXT, undefined, 'extend', 200, + ); + const served = reg.getObject(OBJ); + expect(titles(served)).toEqual(['Tasks', 'Audit trail', 'crm_note']); + const packagedBase = packagedBaseOf(OBJ); + expect(titles(packagedBase)).toEqual(['Tasks', 'Audit trail', 'crm_note']); + expect(titles(read(served, packagedBase))).toEqual(['任务', '审计', 'crm_note']); + }); + + it('leaves the placed title untranslated once a tenant renames it (diverged from the packaged base)', () => { + const reg = withBase(); + reg.registerObject(child('acme_audit', 'Audit') as never, EXT, undefined, 'own'); + reg.registerObject( + { name: OBJ, place: [{ list: 'acme_audit', after: 'crm_task', label: 'Audit trail' }] } as never, + EXT, undefined, 'extend', 200, + ); + const served = reg.getObject(OBJ) as { relatedLists: unknown[] }; + const renamed = { ...served, relatedLists: served.relatedLists.map((e) => + (typeof e === 'object' && (e as { list?: string }).list === 'acme_audit' ? { ...(e as object), label: 'Audit log' } : e)) }; + expect(titles(read(renamed, packagedBaseOf(OBJ)))).toEqual(['任务', 'Audit log', 'crm_note']); + }); + + it('translates the title the paired `.custom` arrangement gives a list', () => { + const reg = withBase(); + reg.registerObject( + { name: OBJ, relatedLists: [{ list: 'crm_note', label: 'Notes' }, 'crm_task'] } as never, + PAIR, undefined, 'extend', 200, + ); + const served = reg.getObject(OBJ); + expect(titles(served)).toEqual(['Notes', 'crm_task']); + const packagedBase = packagedBaseOf(OBJ); + // The arrangement is the customization layer: never part of the packaged base. + expect(titles(packagedBase)).toEqual(['Tasks', 'crm_note']); + expect(titles(read(served, packagedBase, PAIR_BUNDLE))).toEqual(['笔记', 'crm_task']); + }); +}); diff --git a/packages/objectql/src/registry.ts b/packages/objectql/src/registry.ts index 1ecbe1aa56a..e942804d510 100644 --- a/packages/objectql/src/registry.ts +++ b/packages/objectql/src/registry.ts @@ -3652,10 +3652,10 @@ export class SchemaRegistry { * and `/meta` served its label and option labels untranslated in every * locale while the extender's own pack carried them. * - * ⛔ Exactly those two widen: rules by name, and field NAMES the owner does - * not declare. The scalars stay the owner's, and so does every field the - * owner declares, even one an extender redeclares; an extender's - * `fieldPatches` are never folded in. Each must keep reading as diverged from + * ⛔ Exactly three widen: rules by name, field NAMES the owner does not declare, and the + * tabs a code extender places (#36528: the facet's `packagedPlacedRelatedLists`). The scalars + * stay the owner's, and so does every field the owner declares, even one an extender redeclares; + * an extender's `fieldPatches` are never folded in. Each must keep reading as diverged from * the packaged one, or the catalog — which translates the owner's text under * the owner's keys — takes back the case #8037 filed. A tenant overlay and an * extension of tenant provenance (`_provenance: 'org'`) add nothing here: @@ -3664,7 +3664,7 @@ export class SchemaRegistry { * still reads every code extender, disabled ones included.) * * Returns the owner's definition BY REFERENCE when no code extender ships a - * rule or adds a field, and `undefined` exactly where + * rule, adds a field or places a list, and `undefined` exactly where * {@link getPackagedObjectOwner} does. */ getPackagedObjectBase(name: string): ServiceObject | undefined { diff --git a/packages/spec/authorable-surface/system.json b/packages/spec/authorable-surface/system.json index 534120eff7d..a674725026c 100644 --- a/packages/spec/authorable-surface/system.json +++ b/packages/spec/authorable-surface/system.json @@ -858,6 +858,7 @@ "system/ObjectStorageConfig:quota", "system/ObjectStorageConfig:scope", "system/ObjectTranslationData:_actions", + "system/ObjectTranslationData:_relatedLists", "system/ObjectTranslationData:_sections", "system/ObjectTranslationData:_tabs", "system/ObjectTranslationData:_validations", diff --git a/packages/spec/liveness/translation.json b/packages/spec/liveness/translation.json index 3e10f9a5d30..ed9e848b3d7 100644 --- a/packages/spec/liveness/translation.json +++ b/packages/spec/liveness/translation.json @@ -27,7 +27,7 @@ "objects": { "status": "live", "verifiedAt": "2026-08-28", - "evidence": "packages/spec/src/system/i18n-resolver.ts#lookupObjectField (`objects..label` / `pluralLabel` / `description`); packages/spec/src/system/i18n-resolver.ts#lookupObjectFieldAttr (`objects..fields..`); packages/spec/src/system/i18n-resolver.ts#resolveViewLabel (`objects.._views..label`); packages/spec/src/system/i18n-resolver.ts#actionTranslationNode (`objects.._actions`, the one address of a bound action — never followed by globalActions); packages/spec/src/system/i18n-resolver.ts#lookupTabLabel (`objects.._tabs`); ui/packages/i18n/src/useObjectLabel.ts (:397-400 at objectui @940ba24)", + "evidence": "packages/spec/src/system/i18n-resolver.ts#lookupObjectField (`objects..label` / `pluralLabel` / `description`); packages/spec/src/system/i18n-resolver.ts#lookupObjectFieldAttr (`objects..fields..`); packages/spec/src/system/i18n-resolver.ts#resolveViewLabel (`objects.._views..label`); packages/spec/src/system/i18n-resolver.ts#actionTranslationNode (`objects.._actions`, the one address of a bound action — never followed by globalActions); packages/spec/src/system/i18n-resolver.ts#lookupTabLabel (`objects.._tabs`); packages/spec/src/system/i18n-resolver.ts#lookupRelatedListLabel (`objects.._relatedLists`, read by translateObject); ui/packages/i18n/src/useObjectLabel.ts (:397-400 at objectui @940ba24)", "note": "the largest group, fully live: label/pluralLabel/description (translateObject), fields.{label,help,placeholder,options}, _views (resolveViewLabel + empty-state copy), _actions (label/description/confirmText/successMessage/outcomeMessages/params/resultDialog — a bound action's only address; it never falls back to globalActions), _sections (objectui record:details section labels). Served through REST translateMetaItem(s) and the /api/v1/i18n endpoints; objectui re-resolves client-side via the spec-translations transform. 2026-08-28: RE-ANCHORED (commit 8f10a79f7) and REPOINTED — this entry named SIX positions in i18n-resolver.ts and only the first, `:735`, was parsable as a citation at all; it had rotted onto `widgets?: WidgetLike[]` in the `DashboardLike` INTERFACE. The other five (`:751`, `:159`, `:197`, `:873`, `:900`) were bare line suffixes with no path in front of them, so they were never resolved, bounded or key-checked by anything — the largest instance in this batch of the class `flow.status` and `dashboard.widgets.suppressWarnings` also carried. The five anchors above are the five distinct group readers, named. Re-closed by hand against 8cb96ec41." }, "picklists": { diff --git a/packages/spec/src/system/i18n-related-lists-label-36528.test.ts b/packages/spec/src/system/i18n-related-lists-label-36528.test.ts new file mode 100644 index 00000000000..e6473f89fb7 --- /dev/null +++ b/packages/spec/src/system/i18n-related-lists-label-36528.test.ts @@ -0,0 +1,139 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// `objects.._relatedLists..label` — the title an object-form +// `relatedLists` entry declares on the PARENT, and the translator that +// overlays it on the served parent object. +// +// The entry's `label` wins over the child FK's `relatedListTitle`, which the +// bundle already translated on the child; the winning title had no key, so a +// declared record-page tab title printed in the authoring language. + +import { describe, it, expect } from 'vitest'; +import { + ObjectTranslationDataSchema, + TranslationDataSchema, + type TranslationBundle, +} from './translation.zod'; +import { translateMetadataDocument, translateObject } from './i18n-resolver'; +import { ObjectSchema } from '../data/object.zod'; + +/** A parent whose tab list mixes every entry form. */ +const PACKAGED = { + name: 'account', + label: 'Account', + fields: { name: { name: 'name', type: 'text', label: 'Name' } }, + relatedLists: [ + { list: 'contact', label: 'People' }, + { list: 'event.related_to', label: 'Meetings' }, + { list: 'opportunity' }, + 'case', + 'sys_activity', + ], +}; + +const BUNDLE: TranslationBundle = { + 'zh-CN': { + objects: { + account: { + label: '客户', + _relatedLists: { + contact: { label: '联系人' }, + 'event.related_to': { label: '会议' }, + opportunity: { label: '商机' }, + case: { label: '工单' }, + }, + }, + }, + }, +}; + +const clone = (value: V): V => JSON.parse(JSON.stringify(value)); +const listsOf = (out: unknown) => (out as { relatedLists: unknown[] }).relatedLists; + +describe('ObjectTranslationDataSchema — _relatedLists', () => { + it('accepts the key at the bundle and the per-object doors, a dotted list name included', () => { + expect(TranslationDataSchema.safeParse(BUNDLE['zh-CN']).success).toBe(true); + expect(ObjectTranslationDataSchema.safeParse({ _relatedLists: { 'event.related_to': { label: '会议' } } }).success) + .toBe(true); + }); + + it('keeps the leaf closed: `label` is its one key', () => { + const result = TranslationDataSchema.safeParse({ + objects: { account: { _relatedLists: { contact: { label: '联系人', columns: ['name'] } } } }, + }); + expect(result.success).toBe(false); + const issue = result.error!.issues.find((i) => i.code === 'unrecognized_keys'); + expect(issue?.path).toEqual(['objects', 'account', '_relatedLists', 'contact']); + expect(issue?.message).toContain('this related list title translation'); + }); + + it('names `title` on the leaf as a rename onto `label`, and the un-prefixed group as `_relatedLists`', () => { + const leaf = TranslationDataSchema.safeParse({ objects: { account: { _relatedLists: { contact: { title: 'x' } } } } }); + expect(leaf.error?.issues.find((i) => i.code === 'unrecognized_keys')?.message).toContain('`title` → `label`'); + const group = TranslationDataSchema.safeParse({ objects: { account: { relatedLists: { contact: { label: 'x' } } } } }); + expect(group.success).toBe(false); + expect(group.error?.issues.find((i) => i.code === 'unrecognized_keys')?.message) + .toContain('`relatedLists` → `_relatedLists`'); + }); +}); + +describe('translateObject — a relatedLists entry\'s label', () => { + it('serves the translated title on the parent\'s entry, through the type dispatch, and the object still parses', () => { + const out = translateMetadataDocument('object', clone(PACKAGED), BUNDLE, { locale: 'zh-CN' }); + const lists = listsOf(out); + expect(lists[0]).toEqual({ list: 'contact', label: '联系人' }); + // A dotted object.field list is one key, indexed directly. + expect(lists[1]).toEqual({ list: 'event.related_to', label: '会议' }); + expect(ObjectSchema.safeParse(out).success).toBe(true); + }); + + it('swaps nothing in: an entry with no label, a bare name and a built-in tab are served as authored', () => { + const lists = listsOf(translateObject(clone(PACKAGED), BUNDLE, { locale: 'zh-CN' })); + expect(lists[2]).toEqual({ list: 'opportunity' }); + expect(lists[3]).toBe('case'); + expect(lists[4]).toBe('sys_activity'); + }); + + it('keeps an untranslated title as authored, and hands back the same array when nothing matched', () => { + const doc = clone(PACKAGED); + const out = translateObject(doc, BUNDLE, { locale: 'ja-JP' }); + expect(out.relatedLists).toBe(doc.relatedLists); + }); + + it('applies the BCP-47 ladder and the fallback chain, as `_tabs` does', () => { + expect((listsOf(translateObject(clone(PACKAGED), BUNDLE, { locale: 'zh' }))[0] as { label: string }).label) + .toBe('联系人'); + expect( + (listsOf(translateObject(clone(PACKAGED), BUNDLE, { locale: 'fr-FR', fallbackChain: ['zh-CN'] }))[0] as { + label: string; + }).label, + ).toBe('联系人'); + }); + + describe('the catalog loses to an explicit override (ADR-0029 D9.2a)', () => { + it('applies while the served label still equals the packaged entry\'s', () => { + const lists = listsOf(translateObject(clone(PACKAGED), BUNDLE, { locale: 'zh-CN', packagedBase: PACKAGED })); + expect((lists[0] as { label: string }).label).toBe('联系人'); + }); + + it('keeps a label a tenant rewrote, and one on an entry the base does not carry', () => { + const doc = clone(PACKAGED); + (doc.relatedLists[0] as { label: string }).label = 'Key People'; + doc.relatedLists.push({ list: 'case', label: 'Tickets' } as never); + const base = { ...PACKAGED, relatedLists: PACKAGED.relatedLists.slice(0, 4) }; + const lists = listsOf(translateObject(doc, BUNDLE, { locale: 'zh-CN', packagedBase: base })); + expect((lists[0] as { label: string }).label).toBe('Key People'); + expect((lists[5] as { label: string }).label).toBe('Tickets'); + }); + + it('takes the paired package\'s translation for a label it changed', () => { + const doc = clone(PACKAGED); + (doc.relatedLists[0] as { label: string }).label = 'Key People'; + const pairBundle: TranslationBundle = { + 'zh-CN': { objects: { account: { _relatedLists: { contact: { label: '关键联系人' } } } } }, + }; + const lists = listsOf(translateObject(doc, BUNDLE, { locale: 'zh-CN', packagedBase: PACKAGED, pairBundle })); + expect((lists[0] as { label: string }).label).toBe('关键联系人'); + }); + }); +}); diff --git a/packages/spec/src/system/i18n-resolver.ts b/packages/spec/src/system/i18n-resolver.ts index d375ab44781..78cca8dc84b 100644 --- a/packages/spec/src/system/i18n-resolver.ts +++ b/packages/spec/src/system/i18n-resolver.ts @@ -24,12 +24,16 @@ * objects.._actions..params..placeholder * objects.._actions..params..options. * objects.._tabs..label + * objects.._relatedLists..label * objects.._sections..label * objects.._sections..description * objects.._sections..fields..label * objects.._sections..fields..placeholder * objects.._sections..fields..helpText * + * `` is the literal `list` of an object-form `relatedLists` entry on that + * object (`object.field` is one key), see `translateObject`. + * * `` is a form section's own `name` — the served form view's * `config.sections[]`, see {@link translateView}. A section authored without a * `name` has no key and keeps its authored text, its entries' copy included. @@ -5287,6 +5291,90 @@ function translateObjectValidations( return changed ? next : validations; } +/** + * `objects.._relatedLists..label` along the locale chain, the + * `list` indexed directly (a dotted `object.field` is one key, never split); + * `undefined` when no locale of the chain carries a non-empty entry. + */ +function lookupRelatedListLabel( + bundle: TranslationBundle | undefined, + objectName: string, + list: string, + opts?: ResolveOptions, +): string | undefined { + if (!bundle) return undefined; + for (const code of localeChain(opts)) { + const candidate = pickData(bundle, code)?.objects?.[objectName]?._relatedLists?.[list]?.label; + if (typeof candidate === 'string' && candidate.length > 0) return candidate; + } + return undefined; +} + +/** + * Overlay `objects.._relatedLists..label` onto the `label` of + * each object-form entry of an object document's `relatedLists` — the record + * page's tab title and table heading for that list — returning the SAME array + * reference when nothing matched, so {@link translateObject} can leave + * `relatedLists` off its copy. + * + * ## The entry's own label, and nothing in its place + * + * Only an entry that AUTHORS a non-empty `label` is translated. A bare-string + * entry, a built-in tab and an object entry with no `label` keep exactly what + * they serve without a bundle: the console then titles the list from the child + * FK's `relatedListTitle` (translated on the child, see {@link translateObject}) + * or the child object's plural label. A bundle translates an attribute and + * never swaps another in, the rule the field-level `inlineTitle` and + * `relatedListTitle` overlays follow. + * + * The address is keyed by the PARENT (the object that declares the entry) and + * the entry's literal `list` value, `object.field` included as one key. Each + * locale of the chain is asked in order, as `_tabs` is. + * + * ## The catalog loses to an explicit override — ADR-0029 D9.2a + * + * The catalog translates the PACKAGED entry, so the label is judged by + * {@link valueOverridesPackagedBase} (⛔ never a second comparison) against the + * entry naming the same `list` in {@link TranslateDocumentOptions.packagedBase}'s + * `relatedLists`. An entry the base does not carry was authored after the fact + * and its label counts as diverged; no base supplied means nothing is inferred + * and the catalog applies — {@link translateObjectListViews}' edges, unchanged. + */ +function translateObjectRelatedLists( + relatedLists: unknown, + catalogs: LabelCatalogs, + objectName: string, + opts: TranslateDocumentOptions | undefined, +): unknown { + if (!Array.isArray(relatedLists) || !catalogs.unchanged) return relatedLists; + const base = asRecord(opts?.packagedBase); + // The base's own object-form entries — `[]` when the base is known but + // declares none, so every labelled entry on the served document then counts + // as authored. + const packagedEntries = base === undefined + ? undefined + : (Array.isArray(base.relatedLists) ? base.relatedLists : []).map(asRecord); + let changed = false; + const next = relatedLists.map((raw) => { + const entry = asRecord(raw); + if (entry === undefined) return raw; + const list = entry.list; + if (typeof list !== 'string' || list.length === 0) return raw; + if (typeof entry.label !== 'string' || entry.label.length === 0) return raw; + const packagedEntry = packagedEntries === undefined + ? undefined + : packagedEntries.find((candidate) => candidate?.list === list) ?? {}; + const translated = lookupRelatedListLabel( + catalogFor(catalogs, valueOverridesPackagedBase(packagedEntry, 'label', entry.label)), + objectName, list, opts, + ); + if (translated === undefined || translated === entry.label) return raw; + changed = true; + return { ...entry, label: translated }; + }); + return changed ? next : relatedLists; +} + /** * The packaged object's validation rules by `name`, each `conditional` branch * under its own name to {@link MAX_VALIDATION_DEPTH}, for @@ -5452,6 +5540,14 @@ function packagedRulesByName(packagedBase: unknown): Map._relatedLists..label` overlays the `label` of the + * object-form `relatedLists` entry naming `` on THIS object, the parent: + * that label wins over the child FK's `relatedListTitle` on the record page, + * and the console reads it off the served parent. Only an authored label is + * translated — see {@link translateObjectRelatedLists}. */ export function translateObject( doc: T, @@ -5616,6 +5712,8 @@ export function translateObject( const listViews = translateObjectListViews(doc.listViews, catalogs, objectName, opts); const authoredValidations = (doc as { validations?: unknown }).validations; const validations = translateObjectValidations(authoredValidations, bundle, objectName, opts); + const authoredRelatedLists = (doc as { relatedLists?: unknown }).relatedLists; + const relatedLists = translateObjectRelatedLists(authoredRelatedLists, catalogs, objectName, opts); return { ...doc, @@ -5626,6 +5724,7 @@ export function translateObject( ...(actions !== undefined ? { actions } : {}), ...(listViews !== doc.listViews ? { listViews } : {}), ...(validations !== authoredValidations ? { validations } : {}), + ...(relatedLists !== authoredRelatedLists ? { relatedLists } : {}), }; } diff --git a/packages/spec/src/system/translation.zod.ts b/packages/spec/src/system/translation.zod.ts index b91b7d2c59d..fb29fddebae 100644 --- a/packages/spec/src/system/translation.zod.ts +++ b/packages/spec/src/system/translation.zod.ts @@ -561,7 +561,7 @@ export const ObjectTranslationDataSchema = lazySchema(() => strictObject({ // The group prefixes are the whole point of the `_`-prefixed convention, // and the un-prefixed spelling is the one an author reaches for first. views: '_views', actions: '_actions', sections: '_sections', validations: '_validations', - validationRules: '_validations', rules: '_validations', + validationRules: '_validations', rules: '_validations', relatedLists: '_relatedLists', plural: 'pluralLabel', labelPlural: 'pluralLabel', name: 'label', title: 'label', columns: 'fields', properties: 'fields', attributes: 'fields', }, @@ -865,6 +865,40 @@ export const ObjectTranslationDataSchema = lazySchema(() => strictObject({ label: z.string().optional().describe('Translated tab label'), })).optional().describe('Filter-preset tab translations keyed by tab name'), + /** + * Record-page related-list titles keyed by the `list` of an object-form + * `relatedLists` entry (`RelatedListEntryObjectSchema`) on THIS object, the + * parent whose record page draws the list. Convention (overlaid by + * `translateObject` onto the served object's `relatedLists`): + * objects.._relatedLists..label + * + * `` is the entry's literal `list` value, indexed directly and never + * split: `event.related_to` (a child with several relationships to this + * object, written `object.field`) is ONE key, as `resultDialog.fields` keys + * its dotted paths. + * + * **The hole this closes.** An entry's `label` is the tab's title and its + * table's heading, and it wins over the child FK's `relatedListTitle`, which + * the bundle already translated at + * `objects..fields..relatedListTitle`. The winning title had no + * key, so a declared tab title showed its authored text in every locale. + * + * **It translates the entry's own `label` and nothing else.** An entry with + * no `label` keeps the precedence it has without one (the FK's + * `relatedListTitle`, then the child object's plural label, each translated + * where it is declared): a bundle translates an attribute and never swaps + * another in, the rule `inlineTitle` and `relatedListTitle` above follow. A + * bare-string entry and a built-in tab (`sys_attachment`, …) carry no label, + * so they have no key here. + */ + _relatedLists: z.record(z.string(), strictObject({ + surface: 'this related list title translation', + history: TRANSLATION_HISTORY, + aliases: { name: 'label', title: 'label', heading: 'label', text: 'label' }, + }, { + label: z.string().optional().describe("Translated related list title (overlays the relatedLists entry's own `label`)"), + })).optional().describe('Record-page related list titles keyed by the relatedLists entry list name'), + /** * Custom validation-rule messages keyed by rule name * (`ValidationRuleSchema.name`, snake_case).