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
31 changes: 31 additions & 0 deletions .changeset/36528-related-list-label-translation.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions content/docs/protocol/kernel/i18n-standard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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: '确认转换?' } },
},
},
Expand Down Expand Up @@ -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` |
Expand Down
11 changes: 11 additions & 0 deletions content/docs/references/system/translation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Translation data for a single object
| **_actions** | `Record<string, { label?: string; description?: string; confirmText?: string; successMessage?: string; … }>` | optional | Action translations keyed by action name |
| **_sections** | `Record<string, { label?: string; description?: string; fields?: Record<string, object> }>` | optional | Section translations keyed by section name |
| **_tabs** | `Record<string, { label?: string }>` | optional | Filter-preset tab translations keyed by tab name |
| **_relatedLists** | `Record<string, { label?: string }>` | optional | Record-page related list titles keyed by the relatedLists entry list name |
| **_validations** | `Record<string, { message?: string }>` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) |

### Nested Shape: `ObjectTranslationData.fields[string]`
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -215,6 +222,7 @@ Translation data for a single object
| **_actions** | `Record<string, { label?: string; description?: string; confirmText?: string; successMessage?: string; … }>` | optional | Action translations keyed by action name |
| **_sections** | `Record<string, { label?: string; description?: string; fields?: Record<string, object> }>` | optional | Section translations keyed by section name |
| **_tabs** | `Record<string, { label?: string }>` | optional | Filter-preset tab translations keyed by tab name |
| **_relatedLists** | `Record<string, { label?: string }>` | optional | Record-page related list titles keyed by the relatedLists entry list name |
| **_validations** | `Record<string, { message?: string }>` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) |

### Nested Shape: `PlatformTranslationData.picklists[string]`
Expand Down Expand Up @@ -405,6 +413,7 @@ Translation data for a single object
| **_actions** | `Record<string, { label?: string; description?: string; confirmText?: string; successMessage?: string; … }>` | optional | Action translations keyed by action name |
| **_sections** | `Record<string, { label?: string; description?: string; fields?: Record<string, object> }>` | optional | Section translations keyed by section name |
| **_tabs** | `Record<string, { label?: string }>` | optional | Filter-preset tab translations keyed by tab name |
| **_relatedLists** | `Record<string, { label?: string }>` | optional | Record-page related list titles keyed by the relatedLists entry list name |
| **_validations** | `Record<string, { message?: string }>` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) |

### Nested Shape: `ServedTranslationData.picklists[string]`
Expand Down Expand Up @@ -658,6 +667,7 @@ Translation data for a single object
| **_actions** | `Record<string, { label?: string; description?: string; confirmText?: string; successMessage?: string; … }>` | optional | Action translations keyed by action name |
| **_sections** | `Record<string, { label?: string; description?: string; fields?: Record<string, object> }>` | optional | Section translations keyed by section name |
| **_tabs** | `Record<string, { label?: string }>` | optional | Filter-preset tab translations keyed by tab name |
| **_relatedLists** | `Record<string, { label?: string }>` | optional | Record-page related list titles keyed by the relatedLists entry list name |
| **_validations** | `Record<string, { message?: string }>` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) |

### Nested Shape: `TranslationData.picklists[string]`
Expand Down Expand Up @@ -880,6 +890,7 @@ Translation data for a single object
| **_actions** | `Record<string, { label?: string; description?: string; confirmText?: string; successMessage?: string; … }>` | optional | Action translations keyed by action name |
| **_sections** | `Record<string, { label?: string; description?: string; fields?: Record<string, object> }>` | optional | Section translations keyed by section name |
| **_tabs** | `Record<string, { label?: string }>` | optional | Filter-preset tab translations keyed by tab name |
| **_relatedLists** | `Record<string, { label?: string }>` | optional | Record-page related list titles keyed by the relatedLists entry list name |
| **_validations** | `Record<string, { message?: string }>` | optional | Custom validation-rule messages keyed by rule name (`ValidationRuleSchema.name`) |

### Nested Shape: `TranslationItem.picklists[string]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate.

| Dir | Sites |
|---|---|
| `system/` | 408 |
| `system/` | 409 |
144 changes: 144 additions & 0 deletions packages/lint/src/i18n-related-lists-label-36528.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
//
// `objects.<object>._relatedLists.<list>.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<string, unknown>) => ({
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']);
});
});
32 changes: 32 additions & 0 deletions packages/lint/src/i18n-walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.<name>._validations.<rule>.message
* objects.<name>._relatedLists.<list>.label (an object-form `relatedLists`
* entry that authors a `label`)
* objects.<name>._actions.<action>.label
* objects.<name>._actions.<action>.description
* objects.<name>._actions.<action>.confirmText
Expand Down Expand Up @@ -998,6 +1000,28 @@ function pushValidationMessages(
}
}

/**
* Emit `objects.<object>._relatedLists.<list>.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.<o>._sections.<section>.label`) ─────────
//
// A section heading is authored in TWO independent places and rendered from
Expand Down Expand Up @@ -1626,6 +1650,14 @@ export function collectExpectedEntries(

// Custom validation-rule rejection messages (`_validations.<rule>.message`).
pushValidationMessages(out, objectName, obj.validations, 0);

// Record-page related-list titles (`_relatedLists.<list>.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 ──────────────────────────────────────────────
Expand Down
Loading
Loading