Skip to content

Commit a196f6e

Browse files
committed
wip(spec,cli,lint,rest): reports are translatable — a reports group in the translation bundle
Claude-Session: https://claude.ai/code/session_01BUeRMD4VYCYUfzxTKcZFAF Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5f5f0b4 commit a196f6e

17 files changed

Lines changed: 620 additions & 42 deletions

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ Three rules the shape enforces, all of them closed since #4001:
399399

400400
- **The top level is the declared group set and nothing else** — `objects`,
401401
`picklists`, `apps`, `messages`, `globalActions`, `dashboards`, `datasets`,
402-
`pages`, `flows`, `positions`, `permissions`, `metadataForms`,
402+
`reports`, `pages`, `flows`, `positions`, `permissions`, `metadataForms`,
403403
`settingsCommon`. A group invented beside them
404404
(`"account"`, `"fields"`, `"list"`, `"industries"`) is rejected **by name**
405405
at both authoring doors, with the group to use instead named in the
@@ -483,7 +483,7 @@ what the overlay writes back as the node's `title`.
483483
The contract is `t(key, locale, params?)` — the target locale is always passed
484484
explicitly, and the key itself is returned when no translation is found (there
485485
is no `defaultValue` option). The key is a **dot path into `TranslationData`**,
486-
so it starts at one of the thirteen declared groups.
486+
so it starts at one of the fourteen declared groups.
487487

488488
```typescript
489489
const i18n = kernel.getService('i18n');
@@ -1063,6 +1063,7 @@ beneath an action entry are judged the same way under either.
10631063
| `flows.{flow}` | a flow's machine `name`, declared |
10641064
| `positions.{name}` | a position's `name`, declared, or an audience anchor (`everyone`, `guest`) |
10651065
| `permissions.{name}` | a permission set's `name`, declared |
1066+
| `reports.{name}` | a report's `name`, declared |
10661067
| `flows.{flow}.screens.{node}` | the `id` of a `type: 'screen'` node in that flow, nodes nested in loop, parallel and try/catch regions included |
10671068
| `flows.{flow}.screens.{node}.fields.{field}` | a `config.fields[].name` on that screen — an object-form screen (`config.objectName`) declares none, and its input labels live under `objects.{objectName}.fields` |
10681069

‎content/docs/ui/translations.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default defineStack({
7878
| Dashboard global-filter label and static option labels | `dashboards.<name>.globalFilters.<filterName>.label` / `.options.<value>` — the key is the filter's `name`, or its `field` when it authors no `name`; an option is keyed by its `value` spelled as a string |
7979
| Analytics dataset label / description | `datasets.<name>.label` / `description` |
8080
| Dataset dimension and measure labels | `datasets.<name>.dimensions.<dimension>.label` / `datasets.<name>.measures.<measure>.label` |
81+
| Report label / description | `reports.<name>.label` / `description` — keyed by the report's `name`; overlaid on every served report, which is what the console's report index lists and the report page is headed by. A label or description an org re-authored on a packaged report is served as edited |
8182
| Page labels and `page:header` copy | `pages.<name>.label` / `description` / `title` / `subtitle` — on a `kind: 'slotted'` page the header under `slots.header` is the page's header |
8283
| Page component copy, by component id | `pages.<name>.components.<id>.title` / `description` / `label` / `placeholder` / `emptyText` — reached under `regions[].components[]` and `slots.<slot>`, through `properties.children` and a `page:tabs` / `page:accordion` panel's `items[].children` |
8384
| Page tab labels (`page:tabs` items) | `pages.<name>.components.<tabsId>.items.<value>.label` — keyed by the tabs component's `id` and the item's `value`; an item without a `value` has no key (localize it with an inline locale map), and `page:accordion` panels have none |
@@ -89,7 +90,7 @@ export default defineStack({
8990
| A label written as an inline locale map (`label: { en: 'Members', 'zh-CN': '成员' }`) | Nowhere — it is written on the metadata and resolved at render time; see **Current boundaries** below |
9091

9192
The metadata types resolved per request are **object, view, action, app,
92-
dashboard, dataset, page, picklist, position and permission** — a field's labels are translated as part of
93+
dashboard, dataset, report, page, picklist, position and permission** — a field's labels are translated as part of
9394
its object document, and so are the labels of any actions the object declares
9495
inline
9596
(#3370). Before that, an object document went out with its authored action

‎packages/cli/src/utils/i18n-coverage.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface CoverageIssue {
6767
| 'dashboard'
6868
| 'widget'
6969
| 'dataset'
70+
| 'report'
7071
| 'picklist'
7172
| 'page'
7273
| 'flow'
@@ -352,6 +353,11 @@ const COVERAGE_SOURCE: Record<ExpectedEntry['source'], CoverageIssue['source']>
352353
// the `dashboard` bucket: the string is defined once, not once per
353354
// presentation.
354355
dataset: 'dataset',
356+
// Report copy (`reports.<r>.label` / `.description`) — the author's own
357+
// reports, listed by these two strings on the app's report index and headed
358+
// by the label on the report page, so it keeps its own bucket and reports as
359+
// `i18n/missing-report` rather than folding into `dashboard`.
360+
report: 'report',
355361
// Shared option-list copy (`picklists.<p>.label`, `.options.<value>`) — the
356362
// author's own vocabulary, translated once for every field that references
357363
// it, so it keeps its own bucket and reports as `i18n/missing-picklist`.
@@ -396,6 +402,7 @@ const SOURCE_NOUN: Record<CoverageIssue['source'], string> = {
396402
dashboard: 'Dashboard',
397403
widget: 'Widget',
398404
dataset: 'Dataset',
405+
report: 'Report',
399406
picklist: 'Picklist',
400407
page: 'Page',
401408
flow: 'Flow',
@@ -440,6 +447,7 @@ const SOURCE_SURFACE: Record<CoverageIssue['source'], string> = {
440447
dashboard: 'dashboards',
441448
widget: 'widgets',
442449
dataset: 'datasets',
450+
report: 'reports',
443451
picklist: 'picklists',
444452
page: 'pages',
445453
flow: 'flow screens, approval steps, toasts and refusals',

‎packages/cli/src/utils/i18n-extract.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
* datasets.<dataset>.label / .description
103103
* datasets.<dataset>.dimensions.<dim>.label
104104
* datasets.<dataset>.measures.<measure>.label
105+
* reports.<report>.label / .description
105106
* picklists.<picklist>.label
106107
* picklists.<picklist>.options.<value> (a `picklistExtensions` entry's options too)
107108
* pages.<page>.label / .description
@@ -223,6 +224,7 @@ export interface ExpectedEntry {
223224
| 'dashboard'
224225
| 'widget'
225226
| 'dataset'
227+
| 'report'
226228
| 'picklist'
227229
| 'page'
228230
| 'flow'
@@ -1617,6 +1619,9 @@ export function collectExpectedEntries(
16171619
// ── Analytics datasets (`datasets.<name>.…`) ─────────────────────
16181620
walkDatasets(config, out);
16191621

1622+
// ── Reports (`reports.<name>.…`) ─────────────────────────────────
1623+
walkReports(config, out);
1624+
16201625
// ── Shared option lists (`picklists.<name>.…`) ────────────────────
16211626
walkPicklists(config, out);
16221627

@@ -1860,6 +1865,36 @@ function walkPicklists(config: any, out: ExpectedEntry[]): void {
18601865
}
18611866
}
18621867

1868+
// ─── Reports (`reports.<name>.…`) ──────────────────────────────────────
1869+
1870+
/**
1871+
* Emit the report copy surface:
1872+
*
1873+
* reports.<name>.label / .description
1874+
*
1875+
* Read off the stack's `reports[]`. Served through `translateReport`,
1876+
* registered in `METADATA_DOCUMENT_TRANSLATORS`, so the REST boundary
1877+
* localizes `GET /meta/report` (the list the console's report index and report
1878+
* page read); this pass is the half that writes the skeleton and lets
1879+
* `os i18n check` see the gap.
1880+
*
1881+
* `pushOptional` for both keys: a report's `description` is optional at the
1882+
* authoring site, so a string nobody wrote is recorded without an `inline` and
1883+
* never demanded as a translation. A report's `label` is required, so it is
1884+
* always authored text. A joined report's block labels and the embedded
1885+
* chart's copy are not on this face.
1886+
*/
1887+
function walkReports(config: any, out: ExpectedEntry[]): void {
1888+
const reports: any[] = Array.isArray(config?.reports) ? config.reports : [];
1889+
for (const report of reports) {
1890+
if (!report || typeof report !== 'object') continue;
1891+
const name = report.name;
1892+
if (typeof name !== 'string' || name.length === 0) continue;
1893+
pushOptional(out, ['reports', name, 'label'], report.label, 'report');
1894+
pushOptional(out, ['reports', name, 'description'], report.description, 'report');
1895+
}
1896+
}
1897+
18631898
// ─── Security catalog (`positions.<name>.…`, `permissions.<name>.…`) ───
18641899

18651900
/**
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) 2026 ObjectStack contributors. Apache-2.0 license.
2+
//
3+
// `reports.<name>.…` — the extractor walks the report translation group.
4+
//
5+
// A report is listed by its label and description on the app's report index,
6+
// and headed by its label on the report page. Both are served through
7+
// `translateReport`, so without this walk `os i18n extract` scaffolded no key
8+
// for them and `os i18n check` measured a debt of zero while every report
9+
// listed in the authoring language.
10+
11+
import { describe, it, expect } from 'vitest';
12+
import { collectExpectedEntries, extractTranslations } from '../src/utils/i18n-extract.js';
13+
import { computeI18nCoverage } from '../src/utils/i18n-coverage.js';
14+
import { TranslationDataSchema } from '@objectstack/spec/system';
15+
16+
const config = () => ({
17+
reports: [
18+
{
19+
name: 'opps_by_stage',
20+
label: 'Opportunities by Stage',
21+
description: 'Summary of opportunities grouped by stage',
22+
type: 'summary',
23+
dataset: 'pipeline',
24+
rows: ['stage'],
25+
values: ['amount'],
26+
},
27+
// No description: nothing an author wrote, so nothing is demanded.
28+
{ name: 'leads_by_source', label: 'Leads by Source', type: 'summary', dataset: 'leads', values: ['n'] },
29+
],
30+
});
31+
32+
const keysOf = (group: string) =>
33+
collectExpectedEntries(config())
34+
.filter((e) => e.path[0] === group)
35+
.map((e) => e.path.join('.'))
36+
.sort();
37+
38+
describe('i18n extract — the `reports` group', () => {
39+
it('walks each report\'s label and description', () => {
40+
expect(keysOf('reports')).toEqual([
41+
'reports.leads_by_source.description',
42+
'reports.leads_by_source.label',
43+
'reports.opps_by_stage.description',
44+
'reports.opps_by_stage.label',
45+
]);
46+
});
47+
48+
it('seeds authored text and records an unwritten string without demanding it', () => {
49+
const byKey = new Map(collectExpectedEntries(config()).map((e) => [e.path.join('.'), e]));
50+
expect(byKey.get('reports.opps_by_stage.label'))
51+
.toMatchObject({ sourceValue: 'Opportunities by Stage', inline: 'Opportunities by Stage', source: 'report' });
52+
expect(byKey.get('reports.opps_by_stage.description'))
53+
.toMatchObject({ sourceValue: 'Summary of opportunities grouped by stage', source: 'report' });
54+
const unwritten = byKey.get('reports.leads_by_source.description');
55+
expect(unwritten?.sourceValue).toBeUndefined();
56+
expect(unwritten?.inline).toBeUndefined();
57+
});
58+
59+
it('`TranslationDataSchema` accepts a bundle written at the extracted paths', () => {
60+
const out = extractTranslations(config(), { locales: ['zh-CN'] });
61+
const zh = out.bundles['zh-CN'] as any;
62+
expect(Object.keys(zh?.reports ?? {}).sort()).toEqual(['leads_by_source', 'opps_by_stage']);
63+
expect(zh?.reports?.opps_by_stage?.label).toBeDefined();
64+
expect(TranslationDataSchema.safeParse({ reports: zh.reports }).success).toBe(true);
65+
});
66+
67+
it('reports an untranslated label under its own bucket', () => {
68+
const report = computeI18nCoverage({
69+
...config(),
70+
i18n: { supportedLocales: ['en', 'zh-CN'] },
71+
translations: [
72+
{ 'zh-CN': { reports: { opps_by_stage: { label: '各阶段商机', description: '按阶段汇总的商机' } } } },
73+
],
74+
});
75+
const zhIssues = report.issues.filter((i) => i.locale === 'zh-CN');
76+
const keys = zhIssues.map((i) => i.key);
77+
expect(keys).toContain('reports.leads_by_source.label');
78+
expect(keys).not.toContain('reports.opps_by_stage.label');
79+
expect(keys).not.toContain('reports.opps_by_stage.description');
80+
// Nothing authored ⇒ nothing to translate.
81+
expect(keys).not.toContain('reports.leads_by_source.description');
82+
expect(zhIssues.find((i) => i.key === 'reports.leads_by_source.label')?.source).toBe('report');
83+
});
84+
});

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3434,7 +3434,8 @@ const TRANSLATION_TARGET_UNKNOWN_EXPLANATION: RuleExplanation = {
34343434
'`actionUrl`, not its label. `picklists.LIST` a picklist\'s `name` that a package of this ' +
34353435
'stack declares. `positions.NAME` a position\'s `name` that a package of this stack ' +
34363436
'declares, or an audience anchor (`everyone`, `guest`); `permissions.NAME` a permission ' +
3437-
'set\'s `name` that a package of this stack declares.',
3437+
'set\'s `name` that a package of this stack declares. `reports.NAME` a report\'s `name` that ' +
3438+
'a package of this stack declares.',
34383439
// The terminal toast keys are held to `FLOW_TERMINAL_MESSAGE_KEYS` by the rule's test.
34393440
'`flows.FLOW` a flow\'s machine `name`; `.successMessage` / `.errorMessage` a toast the flow ' +
34403441
'itself authors (a bundle cannot add one); `.screens.NODE` the `id` of a `type: \'screen\'` ' +

‎packages/lint/src/validate-translation-references.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4474,3 +4474,41 @@ describe('validateTranslationReferences — the security catalog (positions, per
44744474
.toEqual([]);
44754475
});
44764476
});
4477+
4478+
describe('validateTranslationReferences — reports', () => {
4479+
const stack = (data: Record<string, unknown>, extra: Record<string, unknown> = {}) => ({
4480+
reports: [{ name: 'opps_by_stage', label: 'Opportunities by Stage', type: 'summary', dataset: 'pipeline', values: ['amount'] }],
4481+
...extra,
4482+
translations: [{ en: data }],
4483+
});
4484+
4485+
it('a declared name is clean', () => {
4486+
expect(validateTranslationReferences(stack({
4487+
reports: { opps_by_stage: { label: 'Opportunities by Stage', description: 'Pipeline grouped by stage' } },
4488+
}))).toEqual([]);
4489+
});
4490+
4491+
it('a name no package declares is translation-target-unknown, at the named-item groups\' error', () => {
4492+
const findings = validateTranslationReferences(stack({ reports: { opps_by_stgae: { label: 'x' } } }));
4493+
expect(findings.map((f) => [f.rule, f.severity, f.path, f.where])).toEqual([
4494+
[TRANSLATION_TARGET_UNKNOWN, 'error', 'translations[0].en.reports.opps_by_stgae', 'locale "en" · report "opps_by_stgae"'],
4495+
]);
4496+
expect(findings[0].message).toContain('Did you mean "opps_by_stage"?');
4497+
});
4498+
4499+
it('judges the group against its own collection — a dashboard name under `reports` is an orphan', () => {
4500+
const findings = validateTranslationReferences(stack(
4501+
{ reports: { ops: { label: 'x' } } },
4502+
{ dashboards: [{ name: 'ops', label: 'Operations', widgets: [] }] },
4503+
));
4504+
expect(findings.map((f) => f.path)).toEqual(['translations[0].en.reports.ops']);
4505+
});
4506+
4507+
it('resolves a name a sibling package of the artifact declares', () => {
4508+
const findings = validateTranslationReferences(stack(
4509+
{ reports: { leads_by_source: { label: 'Leads by Source' } } },
4510+
{ packages: [{ manifest: { reports: [{ name: 'leads_by_source', label: '线索来源', type: 'summary', dataset: 'leads', values: ['n'] }] } }] },
4511+
));
4512+
expect(findings).toEqual([]);
4513+
});
4514+
});

‎packages/lint/src/validate-translation-references.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@
155155
* environment, so a key naming one resolves and is never an orphan. Leaf keys
156156
* below the name are the schema's (`label` / `description`, strict).
157157
*
158+
* ── Reports ──────────────────────────────────────────────────────────────
159+
*
160+
* `reports.<name>` resolves against `Report.name`, the name `translateReport`
161+
* looks a served report up by, with the same verdict: a name no package of
162+
* this stack declares is an orphan, `translation-target-unknown` (`error`).
163+
* Leaf keys below the name are the schema's (`label` / `description`, strict).
164+
*
158165
* ── Cross-package objects ────────────────────────────────────────────────
159166
*
160167
* A stack legitimately translates objects it does not define — `sys_user`'s
@@ -199,8 +206,8 @@
199206
* is the one reader of that carrier, and every collection it may be asked for
200207
* is a key whose `COMPOSE_KEY_DISPOSITIONS` disposition puts it inside an
201208
* ADR-0130 D4 entry's assembled body: `objects` (#19064) plus `views`,
202-
* `pages`, `actions`, `apps`, `dashboards` and `flows` (#19349), and
203-
* `positions` and `permissions`.
209+
* `pages`, `actions`, `apps`, `dashboards` and `flows` (#19349),
210+
* `positions` and `permissions`, and `reports`.
204211
*
205212
* ⚠️ `apps` reads BOTH that carrier and `navigationContributions`, and they
206213
* answer different questions — what a sibling DECLARES, and what this package
@@ -507,6 +514,8 @@ interface Universe {
507514
positions: Set<string>;
508515
/** Permission-set names (`PermissionSet.name`) a `permissions.<name>` key may name. */
509516
permissionSets: Set<string>;
517+
/** Report names (`Report.name`) a `reports.<name>` key may name. */
518+
reports: Set<string>;
510519
/**
511520
* Page name (`Page.name`) → every component id the page ADDRESSES
512521
* (`pages.<page>.components.<id>`), with that component's type and, for a
@@ -1680,6 +1689,8 @@ function buildUniverse(stack: AnyRec): Universe {
16801689
const positions = namesOf('positions');
16811690
for (const anchor of AUDIENCE_ANCHOR_POSITIONS) positions.add(anchor);
16821691
const permissionSets = namesOf('permissions');
1692+
// `reports` carries disposition `concat` too, so a sibling's reports resolve.
1693+
const reports = namesOf('reports');
16831694

16841695
return {
16851696
objects,
@@ -1694,6 +1705,7 @@ function buildUniverse(stack: AnyRec): Universe {
16941705
extendedPicklists,
16951706
positions,
16961707
permissionSets,
1708+
reports,
16971709
pages,
16981710
};
16991711
}
@@ -2146,12 +2158,13 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind
21462158
});
21472159
}
21482160

2149-
// ── positions.<name> / permissions.<name> ─────────────────────────
2150-
const securityCatalog = [
2161+
// ── positions.<name> / permissions.<name> / reports.<name> ────────
2162+
const namedItemGroups = [
21512163
{ group: 'positions', noun: 'position', known: universe.positions, hint: "Match the key to a position's `name`, or drop it." },
21522164
{ group: 'permissions', noun: 'permission set', known: universe.permissionSets, hint: "Match the key to a permission set's `name`, or drop it." },
2165+
{ group: 'reports', noun: 'report', known: universe.reports, hint: "Match the key to a report's `name`, or drop it." },
21532166
] as const;
2154-
for (const { group, noun, known, hint } of securityCatalog) {
2167+
for (const { group, noun, known, hint } of namedItemGroups) {
21552168
for (const name of Object.keys(asRecord(rawData[group]))) {
21562169
if (known.has(name)) continue;
21572170
orphan(

0 commit comments

Comments
 (0)