diff --git a/.changeset/34939-translation-mappings.md b/.changeset/34939-translation-mappings.md new file mode 100644 index 00000000000..da8e19e63a0 --- /dev/null +++ b/.changeset/34939-translation-mappings.md @@ -0,0 +1,26 @@ +--- +'@objectstack/spec': minor +'@objectstack/metadata-protocol': minor +'@objectstack/rest': minor +'@objectstack/lint': minor +'@objectstack/cli': minor +'@object-ui/app-shell': minor +'@object-ui/i18n': minor +--- + +feat(spec): a named import mapping's label is translatable at `mappings.NAME.label` + +Clause-②: yes (widening) — a new optional translation group `mappings` (one key per mapping, `label`) on `TranslationDataSchema`, `PlatformTranslationDataSchema`, `ServedTranslationDataSchema` and `TranslationItemSchema`, a new `translateMapping` export from `@objectstack/spec/system` registered for the `mapping` type, and a new `ObjectStackProtocolImplementation.getPackagedMappingBase`; nothing that parsed before is refused +Metadata-protocol: added +Skills-docs: follow-up owed — #34962 (skills/objectstack-i18n/SKILL.md group list) + +An import mapping's `label` is the name the import wizard offers it by, and until now it showed the authored text in every locale: the bundle had no key for it. A bundle now translates it: + +```ts +'zh-CN': { mappings: { crm_lead_feed: { label: '线索导入' } } } +``` + +- `GET /meta/mapping` (list and item) serves the label in the reader's locale. A shipped mapping overridden through its `.custom` pair follows the ADR-0146 D2 order every other translated label follows: a label the override changed keeps its own text unless the pair translates it, and a label it left alone takes the pair's translation, then the package's. The packaged base is now available for `mapping` (`getPackagedMappingBase`), so the override's label is judged against it. +- Only `label` has a key. A mapping declares no `description`, and its `fieldMapping` holds column and field names rather than copy — the refusal for either names where to translate instead (a target field's label is `objects.OBJECT.fields.FIELD.label`). The singular `mapping` and the label aliases `name` / `title` are refused with the declared spelling named. +- `os i18n extract` scaffolds the key, `os i18n check` reports a gap as `i18n/missing-mapping`, and `os validate` reports a key naming no mapping of the stack as `translation-target-unknown`, with the nearest name suggested. +- Studio's translation preview shows the group as **Import Mappings** (导入映射), and the Studio translation table walks it. diff --git a/content/docs/data-modeling/import-mappings.mdx b/content/docs/data-modeling/import-mappings.mdx index bbe84e562f6..548a4106050 100644 --- a/content/docs/data-modeling/import-mappings.mdx +++ b/content/docs/data-modeling/import-mappings.mdx @@ -116,7 +116,7 @@ mapping under its own name. | Key | Type | What it does | |:---|:---|:---| | `name` | `string` (snake_case) | The id `mappingName` resolves. Missing artifact → `404 MAPPING_NOT_FOUND`. | -| `label` | `string` | Display text in a saved-mapping picker. Falls back to `name`. | +| `label` | `string` | Display text in a saved-mapping picker (the import wizard). Falls back to `name`. Translated per locale at `mappings..label` in the app's translation bundle — see [Translations](/docs/ui/translations). | | `sourceFormat` | `'csv' \| 'json' \| 'xml' \| 'sql'` | Declared payload format, checked against what the request actually sent. Defaults to `csv`. See [the format gate](#rejections-before-any-row-is-read). | | `targetObject` | `string` | The object this mapping is for. Must equal the object in the URL. | | `fieldMapping` | `ImportFieldMapping[]` | The projection itself — one entry per target field. | diff --git a/content/docs/protocol/kernel/i18n-standard.mdx b/content/docs/protocol/kernel/i18n-standard.mdx index cf706e24f18..4d042a8fb50 100644 --- a/content/docs/protocol/kernel/i18n-standard.mdx +++ b/content/docs/protocol/kernel/i18n-standard.mdx @@ -493,7 +493,7 @@ Three rules the shape enforces, all of them closed since #4001: - **The top level is the declared group set and nothing else** — `objects`, `picklists`, `apps`, `messages`, `globalActions`, `dashboards`, `datasets`, `reports`, `pages`, `flows`, `hooks`, `positions`, `permissions`, `books`, - `metadataForms`, `settingsCommon`. A group invented beside them + `mappings`, `metadataForms`, `settingsCommon`. A group invented beside them (`"account"`, `"fields"`, `"list"`, `"industries"`) is rejected **by name** at both authoring doors, with the group to use instead named in the rejection. @@ -582,7 +582,7 @@ what the overlay writes back as the node's `title`. The contract is `t(key, locale, params?)` — the target locale is always passed explicitly, and the key itself is returned when no translation is found (there is no `defaultValue` option). The key is a **dot path into `TranslationData`**, -so it starts at one of the sixteen declared groups. +so it starts at one of the seventeen declared groups. ```typescript const i18n = kernel.getService('i18n'); diff --git a/content/docs/references/api/protocol.mdx b/content/docs/references/api/protocol.mdx index e35eb7a6796..353c2277019 100644 --- a/content/docs/references/api/protocol.mdx +++ b/content/docs/references/api/protocol.mdx @@ -1882,6 +1882,7 @@ The published metadata item body, opaque by ruling (1C). Shape is the item's own | **positions** | `Record` | optional | Position translations keyed by position name | | **permissions** | `Record` | optional | Permission-set translations keyed by permission-set name | | **books** | `Record }>` | optional | Doc-book translations keyed by book name | +| **mappings** | `Record` | optional | Import-mapping translations keyed by mapping name | | **settingsCommon** | `{ sourceLabels?: object }` | optional | Cross-namespace Settings UI strings | | **settings** | `Record; keys?: Record; … }>` | optional | Settings manifest translations keyed by namespace | diff --git a/content/docs/references/data/mapping.mdx b/content/docs/references/data/mapping.mdx index 9e9bc95663d..f14a3190a2c 100644 --- a/content/docs/references/data/mapping.mdx +++ b/content/docs/references/data/mapping.mdx @@ -43,7 +43,7 @@ const result = ImportFieldMappingSchema.parse(data); | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | | **name** | `string` | ✅ | Mapping unique name (lowercase snake_case) | -| **label** | `string` | optional | | +| **label** | `string` | optional | Display label, shown where the mapping is offered by name (the import wizard); translated per locale at `mappings..label` in the translation bundle | | **sourceFormat** | `Enum<'csv' \| 'json' \| 'xml' \| 'sql'>` | optional (default: `"csv"`) | | | **targetObject** | `string` | ✅ | Target Object Name | | **fieldMapping** | `{ source: string \| string[]; target: string \| string[]; transform?: Enum<'none' \| 'constant' \| 'lookup' \| 'split' \| 'join' \| 'javascript' \| 'map'>; params?: object }[]` | ✅ | | diff --git a/content/docs/references/system/translation.mdx b/content/docs/references/system/translation.mdx index 825b2261401..a798e21c4e9 100644 --- a/content/docs/references/system/translation.mdx +++ b/content/docs/references/system/translation.mdx @@ -195,6 +195,7 @@ Platform translation data — the per-app groups plus the platform-only `setting | **positions** | `Record` | optional | Position translations keyed by position name | | **permissions** | `Record` | optional | Permission-set translations keyed by permission-set name | | **books** | `Record }>` | optional | Doc-book translations keyed by book name | +| **mappings** | `Record` | optional | Import-mapping translations keyed by mapping name | | **metadataForms** | `Record; fields?: Record }>` | optional | Translations for metadata-type configuration forms keyed by metadata type | | **settingsCommon** | `{ sourceLabels?: object }` | optional | Cross-namespace Settings UI strings | | **settings** | `Record; keys?: Record; … }>` | optional | Settings manifest translations keyed by namespace | @@ -326,6 +327,12 @@ Translation data for a single object | **description** | `string` | optional | Translated book description — overlays the book's own `description` | | **groups** | `Record` | optional | Group (section) translations keyed by the group `key` | +### Nested Shape: `PlatformTranslationData.mappings[string]` + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **label** | `string` | optional | Translated import mapping label — overlays the mapping's own `label` | + ### Nested Shape: `PlatformTranslationData.metadataForms[string]` | Property | Type | Required | Description | @@ -377,6 +384,7 @@ Served translation data — the platform groups the browser reads, without the s | **positions** | `Record` | optional | Position translations keyed by position name | | **permissions** | `Record` | optional | Permission-set translations keyed by permission-set name | | **books** | `Record }>` | optional | Doc-book translations keyed by book name | +| **mappings** | `Record` | optional | Import-mapping translations keyed by mapping name | | **settingsCommon** | `{ sourceLabels?: object }` | optional | Cross-namespace Settings UI strings | | **settings** | `Record; keys?: Record; … }>` | optional | Settings manifest translations keyed by namespace | @@ -507,6 +515,12 @@ Translation data for a single object | **description** | `string` | optional | Translated book description — overlays the book's own `description` | | **groups** | `Record` | optional | Group (section) translations keyed by the group `key` | +### Nested Shape: `ServedTranslationData.mappings[string]` + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **label** | `string` | optional | Translated import mapping label — overlays the mapping's own `label` | + ### Nested Shape: `ServedTranslationData.settingsCommon` | Property | Type | Required | Description | @@ -621,6 +635,7 @@ Per-app translation data for objects, apps, and UI messages | **positions** | `Record` | optional | Position translations keyed by position name | | **permissions** | `Record` | optional | Permission-set translations keyed by permission-set name | | **books** | `Record }>` | optional | Doc-book translations keyed by book name | +| **mappings** | `Record` | optional | Import-mapping translations keyed by mapping name | | **metadataForms** | `Record; fields?: Record }>` | optional | Translations for metadata-type configuration forms keyed by metadata type | | **settingsCommon** | `{ sourceLabels?: object }` | optional | Cross-namespace Settings UI strings | @@ -751,6 +766,12 @@ Translation data for a single object | **description** | `string` | optional | Translated book description — overlays the book's own `description` | | **groups** | `Record` | optional | Group (section) translations keyed by the group `key` | +### Nested Shape: `TranslationData.mappings[string]` + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **label** | `string` | optional | Translated import mapping label — overlays the mapping's own `label` | + ### Nested Shape: `TranslationData.metadataForms[string]` | Property | Type | Required | Description | @@ -823,6 +844,7 @@ One locale of translations — the `translation` metadata type | **positions** | `Record` | optional | Position translations keyed by position name | | **permissions** | `Record` | optional | Permission-set translations keyed by permission-set name | | **books** | `Record }>` | optional | Doc-book translations keyed by book name | +| **mappings** | `Record` | optional | Import-mapping translations keyed by mapping name | | **metadataForms** | `Record; fields?: Record }>` | optional | Translations for metadata-type configuration forms keyed by metadata type | | **settingsCommon** | `{ sourceLabels?: object }` | optional | Cross-namespace Settings UI strings | | **locale** | `string` | ✅ | BCP-47 locale this item translates (e.g. "zh-CN") | @@ -964,6 +986,12 @@ Translation data for a single object | **description** | `string` | optional | Translated book description — overlays the book's own `description` | | **groups** | `Record` | optional | Group (section) translations keyed by the group `key` | +### Nested Shape: `TranslationItem.mappings[string]` + +| Property | Type | Required | Description | +| :--- | :--- | :--- | :--- | +| **label** | `string` | optional | Translated import mapping label — overlays the mapping's own `label` | + ### Nested Shape: `TranslationItem.metadataForms[string]` | Property | Type | Required | Description | diff --git a/content/docs/ui/translations.mdx b/content/docs/ui/translations.mdx index 460b93a28ae..342877ff272 100644 --- a/content/docs/ui/translations.mdx +++ b/content/docs/ui/translations.mdx @@ -98,12 +98,13 @@ export default defineStack({ | Position label / description | `positions..label` / `description` — keyed by the position's `name`; overlaid on every served position, which is the list the console's position picker draws | | Permission-set label / description | `permissions..label` / `description` — the group is spelled as the stack spells the collection (`permissions[]`), keyed by the set's `name` | | Doc book title, description and section titles | `books..label` / `description` / `groups..label` — keyed by the book's `name` and each group's `key`; overlaid on every served book and on the book tree, which is what the docs sidebar draws. A doc's own title and body localize through `doc.translations` instead | +| Import mapping label | `mappings..label` — keyed by the mapping's `name`; overlaid on every served mapping, which is the list the import wizard offers by name. A mapping's `fieldMapping` holds column and field names, not copy: a target field's label is translated under `objects..fields..label` | | Global actions, messages | `globalActions`, `messages` | | Settings UI shell copy (the source badge on a settings row) | `settingsCommon.sourceLabels.` — the per-namespace settings copy under `settings` is **platform-only**: an app bundle carrying it is refused by name, and the platform's own strings are translated in `@objectstack/service-settings`'s bundle | | 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 | The metadata types resolved per request are **object, view, action, app, -dashboard, dataset, report, page, picklist, position, permission and book** — a field's labels are translated as part of +dashboard, dataset, report, page, picklist, position, permission, book and mapping** — a field's labels are translated as part of its object document, and so are the labels of any actions the object declares inline (#3370). Before that, an object document went out with its authored action 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 74a96565703..1df2ce1f97b 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/` | 405 | +| `system/` | 406 | diff --git a/docs/qa/platform-checklist/areas/i18n.json b/docs/qa/platform-checklist/areas/i18n.json index 4ebc7f6fa7e..c5d154bad2e 100644 --- a/docs/qa/platform-checklist/areas/i18n.json +++ b/docs/qa/platform-checklist/areas/i18n.json @@ -185,7 +185,7 @@ "title": "Every translatable surface localizes on a zh-CN session — one pass over the full translation-group vocabulary, plus the runtime i18n routes it resolves through", "since": "v15", "status": "active", - "revision": 15, + "revision": 16, "priority": "P1", "surface": "browser", "personas": ["admin on a zh-CN session"], @@ -268,7 +268,7 @@ "evidence": "the /i18n/locales response" }, { - "clause": "GET /i18n/translations/:locale returns a non-empty bundle whose key paths all sit within the declared translation-group vocabulary (ServedTranslationDataSchema — the SERVED document is the merged tree's platform face, PlatformTranslationDataSchema's seventeen groups (TranslationDataSchema's sixteen per-app groups, hooks included, plus the platform-only `settings`), less metadataForms, the one server-resolved group (SERVER_RESOLVED_TRANSLATION_GROUPS), so sixteen groups: apps, books, dashboards, datasets, flows, globalActions, hooks, messages, objects, pages, permissions, picklists, positions, reports, settings, settingsCommon) — a key outside the declared groups, or a raw dotted key handed to a consumer, is the silent-strip class", + "clause": "GET /i18n/translations/:locale returns a non-empty bundle whose key paths all sit within the declared translation-group vocabulary (ServedTranslationDataSchema — the SERVED document is the merged tree's platform face, PlatformTranslationDataSchema's eighteen groups (TranslationDataSchema's seventeen per-app groups, hooks and mappings included, plus the platform-only `settings`), less metadataForms, the one server-resolved group (SERVER_RESOLVED_TRANSLATION_GROUPS), so seventeen groups: apps, books, dashboards, datasets, flows, globalActions, hooks, mappings, messages, objects, pages, permissions, picklists, positions, reports, settings, settingsCommon) — a key outside the declared groups, or a raw dotted key handed to a consumer, is the silent-strip class", "oracle": "api", "verify": "translations for zh-CN is non-empty; spot-check that sampled keys resolve under objects/_views/_actions/_sections/apps.navigation/dashboards/pages/settings groups, not a fourth dialect", "evidence": "the /translations/zh-CN response + the key check" @@ -321,7 +321,7 @@ "ref": "objectui code under ui/, for acceptance[5]'s dialog COPY only: ui/packages/components/src/__tests__/page-header-action-i18n.test.tsx ('renders the translated button AND opens the confirm dialog with the translated body', 'passes the translated successMessage to the toast') + ui/packages/plugin-detail/src/renderers/__tests__/record-quick-actions.actionText-i18n.test.tsx ('resolves the button AND the confirm dialog body from the same bundle entry', 'resolves successMessage from the same entry'). Each runs the real ActionRunner under a real I18nProvider holding a zh-CN `_actions.NAME` entry, but the action handler, the confirm handler and the toast handler are vi.fn stubs: no request leaves the test, so acceptance[5]'s network clause (the toast attached to a real 2xx round-trip) stays the run's. Run them from this checkout's ui/ directory, where the vitest config lives: neither package carries its own, and each package's test script is `vitest run --root ../..`. The command is `cd ui && pnpm exec vitest run --maxWorkers=1 packages/components/src/__tests__/page-header-action-i18n.test.tsx packages/plugin-detail/src/renderers/__tests__/record-quick-actions.actionText-i18n.test.tsx` and cite the output naming the commit (QA run #23951 ran them in objectui at daeb77fc84dd, 2 files, 7/7). acceptance[6], [7] and [9] have no pin: packages/qa/dogfood/test/showcase-anonymous-deny-surfaces.dogfood.test.ts reaches the i18n routes over HTTP (I18N_FACES, the signed-in member's 200 control), but asserts only that en and zh-CN are among the locales and one translated label, never the exact locale set, the group vocabulary or the zz-ZZ empty-map shape. Every other clause still needs the run" }, "source": [ - "packages/spec/src/system/translation.zod.ts#appTranslationDataShape (appTranslationDataShape — the fifteen-group vocabulary an APPLICATION may author: objects (with _views/_actions/_sections), picklists, apps (navigation), messages, globalActions, dashboards, datasets, reports, pages, flows, positions, permissions, books, metadataForms, settingsCommon. `settings` is platform-only since #15178 and lives in platformSettingsShape, spread into PlatformTranslationDataSchema only — TranslationItemSchema refuses it too since #19620)", + "packages/spec/src/system/translation.zod.ts#appTranslationDataShape (appTranslationDataShape — the seventeen-group vocabulary an APPLICATION may author: objects (with _views/_actions/_sections), picklists, apps (navigation), messages, globalActions, dashboards, datasets, reports, pages, flows, hooks, positions, permissions, books, mappings, metadataForms, settingsCommon. `settings` is platform-only since #15178 and lives in platformSettingsShape, spread into PlatformTranslationDataSchema only — TranslationItemSchema refuses it too since #19620)", "examples/app-showcase/src/system/translations/index.ts (full-column coverage rationale)", "packages/services/service-i18n/src/i18n-service-plugin.ts#i18n (GET /i18n/locales | /translations/:locale | /labels/:object/:locale; { success, data } envelope #3636/#3675; resolveObjectFieldLabels nested shape #3778/#3833; the plugin mount and the dispatcher /i18n domain serve the same routes interchangeably)", "packages/services/service-i18n/src/file-i18n-adapter.ts#getLocales (getLocales / getTranslations — unloaded locale → {}; fallbackLocale applies per-KEY in t(), not to the bulk route)", @@ -368,6 +368,12 @@ "date": "2026-11-15", "change": "verify-, step- and fixture-text correction, no clause change. acceptance[2].verify: the showcase's coverage baseline reads 317, not 414. fixtures.knownGaps[3]: the revoke confirm has now been driven live. steps[18]: the task record page draws no activity timeline; the feed is read on the inbox popover's 活动动态 tab or GET /api/v1/data/sys_activity. Read from source at base 895783a1. Source records: QA record #33853 (comment 6894307378) on #33761. Batch D of the #33761 close-out, card #33966", "ref": "#33984" + }, + { + "revision": 16, + "date": "2026-11-17", + "change": "acceptance[7].clause and the appTranslationDataShape source line: count-and-list correction, no change of the clause's meaning. The clause still scores every served key against the declared vocabulary; that vocabulary gained the `mappings` group (a named import mapping's label, mappings.NAME.label), so the served platform face is eighteen groups, the per-app face seventeen, and the scored set seventeen with mappings named. The source line also named fifteen groups without hooks, stale before this change; it now names all seventeen. The showcase bundle serves mappings.showcase_inquiry_feed, which the old list would have scored as outside the vocabulary. Read from source at base 0465f4aa", + "ref": "#34939" } ] }, diff --git a/examples/app-showcase/src/system/translations/index.ts b/examples/app-showcase/src/system/translations/index.ts index bf9a9f13546..c1d78de908d 100644 --- a/examples/app-showcase/src/system/translations/index.ts +++ b/examples/app-showcase/src/system/translations/index.ts @@ -1548,5 +1548,10 @@ export const ShowcaseTranslationBundle = { }, }, }, + // The named import mapping, as the import wizard offers it by name. + // Counted by `check-i18n-coverage` like the groups above (#34939). + mappings: { + showcase_inquiry_feed: { label: '询盘导入(营销 CSV)' }, + }, }, }; diff --git a/packages/cli/src/utils/i18n-coverage.ts b/packages/cli/src/utils/i18n-coverage.ts index 33b59697b08..941dc4c17df 100644 --- a/packages/cli/src/utils/i18n-coverage.ts +++ b/packages/cli/src/utils/i18n-coverage.ts @@ -77,6 +77,7 @@ export interface CoverageIssue { | 'position' | 'permission' | 'book' + | 'mapping' | 'metadataForm'; /** Human-readable explanation. */ message: string; @@ -388,6 +389,9 @@ const COVERAGE_SOURCE: Record // `books..groups..label`) — the title and section titles of a docs // sidebar, reported as `i18n/missing-book` (#26690). book: 'book', + // A named import mapping's label (`mappings..label`) — the name the + // import wizard offers it by, reported as `i18n/missing-mapping` (#34939). + mapping: 'mapping', metadataType: 'metadataForm', metadataFormSection: 'metadataForm', metadataFormField: 'metadataForm', @@ -414,6 +418,7 @@ const SOURCE_NOUN: Record = { position: 'Position', permission: 'Permission set', book: 'Book', + mapping: 'Import mapping', metadataForm: 'Metadata form', }; @@ -461,6 +466,7 @@ const SOURCE_SURFACE: Record = { position: 'positions', permission: 'permission sets', book: 'doc books', + mapping: 'import mappings', metadataForm: 'metadata forms', }; diff --git a/packages/cli/test/i18n-mapping-walk.test.ts b/packages/cli/test/i18n-mapping-walk.test.ts new file mode 100644 index 00000000000..288cb7b0dea --- /dev/null +++ b/packages/cli/test/i18n-mapping-walk.test.ts @@ -0,0 +1,61 @@ +// Copyright (c) 2026 ObjectStack contributors. Apache-2.0 license. +// +// `mappings..label` — the extractor walks a named import mapping's +// translation group (#34939). +// +// The import wizard offers a shipped mapping by its label, and +// `translateMapping` overlays it from the bundle. Without this walk +// `os i18n extract` would scaffold no key for it and `os i18n check` would +// measure a debt of zero while the wizard showed the authoring language. + +import { describe, it, expect } from 'vitest'; +import { collectExpectedEntries, extractTranslations } from '../src/utils/i18n-bundle-extract.js'; +import { computeI18nCoverage } from '../src/utils/i18n-coverage.js'; +import { TranslationDataSchema } from '@objectstack/spec/system'; + +const config = () => ({ + mappings: [ + { + name: 'lead_feed', + label: 'Lead feed (CSV)', + targetObject: 'lead', + fieldMapping: [{ source: 'Company', target: 'company' }], + }, + { name: 'contact_feed', label: 'Contact feed', targetObject: 'contact', fieldMapping: [] }, + // No label: nothing an author wrote, so nothing is demanded. + { name: 'unlabelled_feed', targetObject: 'lead', fieldMapping: [] }, + ], +}); + +describe('i18n extract — the `mappings` group', () => { + it('walks each mapping\'s label, and nothing of its field mapping', () => { + const keys = collectExpectedEntries(config()) + .filter((e) => e.path[0] === 'mappings') + .map((e) => e.path.join('.')) + .sort(); + expect(keys).toEqual(['mappings.contact_feed.label', 'mappings.lead_feed.label', 'mappings.unlabelled_feed.label']); + }); + + it('`TranslationDataSchema` accepts a bundle written at the extracted paths', () => { + const out = extractTranslations(config(), { locales: ['zh-CN'] }); + const zh = out.bundles['zh-CN'] as any; + // A mapping with no label has no source text to scaffold. + expect(Object.keys(zh?.mappings ?? {}).sort()).toEqual(['contact_feed', 'lead_feed']); + expect(TranslationDataSchema.safeParse({ mappings: zh.mappings }).success).toBe(true); + }); + + it('reports an untranslated label under its own bucket', () => { + const report = computeI18nCoverage({ + ...config(), + i18n: { supportedLocales: ['en', 'zh-CN'] }, + translations: [{ 'zh-CN': { mappings: { lead_feed: { label: '线索导入(CSV)' } } } }], + }); + const zhIssues = report.issues.filter((i) => i.locale === 'zh-CN'); + const missing = zhIssues.map((i) => i.key); + expect(missing).toContain('mappings.contact_feed.label'); + expect(missing).not.toContain('mappings.lead_feed.label'); + // Nothing authored ⇒ nothing to translate. + expect(missing).not.toContain('mappings.unlabelled_feed.label'); + expect(zhIssues.find((i) => i.key === 'mappings.contact_feed.label')?.source).toBe('mapping'); + }); +}); diff --git a/packages/lint/src/i18n-walk.test.ts b/packages/lint/src/i18n-walk.test.ts index a6c92e201a8..dfe788a4561 100644 --- a/packages/lint/src/i18n-walk.test.ts +++ b/packages/lint/src/i18n-walk.test.ts @@ -82,6 +82,27 @@ describe('collectExpectedEntries — a hook\'s declared texts (#34374)', () => { }); }); +describe('collectExpectedEntries — a named import mapping\'s label', () => { + const entries = collectExpectedEntries({ + mappings: [ + { name: 'lead_feed', label: 'Lead feed', targetObject: 'lead', fieldMapping: [{ source: 'Company', target: 'company' }] }, + { name: 'unlabelled_feed', targetObject: 'lead', fieldMapping: [] }, + ], + }, { warnedGroups: new Set() }); + + it('yields mappings..label with the authored label, from the mapping', () => { + const entry = entries.find((e) => e.path.join('.') === 'mappings.lead_feed.label'); + expect(entry?.sourceValue).toBe('Lead feed'); + expect(entry?.source).toBe('mapping'); + }); + + it('keys nothing from the field mapping, and no authored text for a mapping with no label', () => { + const keys = entries.map((e) => e.path.join('.')); + expect(keys.filter((k) => k.startsWith('mappings.lead_feed.'))).toEqual(['mappings.lead_feed.label']); + expect(entries.find((e) => e.path.join('.') === 'mappings.unlabelled_feed.label')?.sourceValue).toBeUndefined(); + }); +}); + describe('authorWarnedTranslationGroups on the shipped ledger', () => { // A browser reads no ledger file, so there the default leaves no group out. // That matches the CLI only while the ledger warns on no translation group; diff --git a/packages/lint/src/i18n-walk.ts b/packages/lint/src/i18n-walk.ts index 7d0082035b1..9063fd3a3d3 100644 --- a/packages/lint/src/i18n-walk.ts +++ b/packages/lint/src/i18n-walk.ts @@ -150,6 +150,7 @@ * permissions..label / .description * books..label / .description * books..groups..label (a doc book's section title, #26690) + * mappings..label (a named import mapping's label) * metadataForms..label / .description * metadataForms..sections.
.label / .description * metadataForms..fields..label / .helpText / .placeholder @@ -260,6 +261,7 @@ export interface ExpectedEntry { | 'position' | 'permission' | 'book' + | 'mapping' | 'metadataType' | 'metadataFormSection' | 'metadataFormField'; @@ -1779,6 +1781,9 @@ export function collectExpectedEntries( // ── Doc books (`books..…`) ────────────────────────────────── walkBooks(config, out); + // ── Import mappings (`mappings..label`) ───────────────────── + walkMappings(config, out); + // ── Pages + their `page:header` copy ────────────────────────────── const pages: any[] = Array.isArray(config?.pages) ? config.pages : []; for (const page of pages) { @@ -2131,6 +2136,25 @@ function walkBooks(config: any, out: ExpectedEntry[]): void { } } +// ─── Import mappings (`mappings..label`) ────────────────────────── + +/** + * Emit a named import mapping's label: `mappings..label`, the key + * `translateMapping` reads. The import wizard offers a mapping by this label. + * The label is optional on the schema, so it is recorded with + * {@link pushOptional}; a mapping's `fieldMapping` is column and field names, + * not copy, and has no key. + */ +function walkMappings(config: any, out: ExpectedEntry[]): void { + const mappings: any[] = Array.isArray(config?.mappings) ? config.mappings : []; + for (const mapping of mappings) { + if (!mapping || typeof mapping !== 'object') continue; + const name = mapping.name; + if (typeof name !== 'string' || name.length === 0) continue; + pushOptional(out, ['mappings', name, 'label'], mapping.label, 'mapping'); + } +} + // ─── Screen flows (`flows..screens..…`) ───────────────── /** diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index 4f0a88033d8..7e911f656de 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -4332,7 +4332,8 @@ const TRANSLATION_TARGET_UNKNOWN_EXPLANATION: RuleExplanation = { 'set\'s `name` that a package of this stack declares. `reports.NAME` a report\'s `name` that ' + 'a package of this stack declares. `books.BOOK` a doc book\'s `name` that a package of this ' + 'stack declares, or a package id (its implicit book), and `.groups.KEY` a group `key` that ' + - 'book declares, not its label.', + 'book declares, not its label. `mappings.MAPPING` an import mapping\'s `name` that a ' + + 'package of this stack declares.', // The terminal toast keys are held to `FLOW_TERMINAL_MESSAGE_KEYS` by the rule's test. '`flows.FLOW` a flow\'s machine `name`; `.successMessage` / `.errorMessage` a toast the flow ' + 'itself authors (a bundle cannot add one); `.screens.NODE` the `id` of a `type: \'screen\'` ' + diff --git a/packages/lint/src/validate-translation-references.test.ts b/packages/lint/src/validate-translation-references.test.ts index 60c323d5086..f5778376d4f 100644 --- a/packages/lint/src/validate-translation-references.test.ts +++ b/packages/lint/src/validate-translation-references.test.ts @@ -4969,6 +4969,42 @@ describe('validateTranslationReferences — reports', () => { }); }); +describe('validateTranslationReferences — import mappings', () => { + const stack = (data: Record, extra: Record = {}) => ({ + mappings: [{ name: 'lead_feed', label: 'Lead feed', targetObject: 'lead', fieldMapping: [{ source: 'Company', target: 'company' }] }], + ...extra, + translations: [{ en: data }], + }); + + it('a declared name is clean', () => { + expect(validateTranslationReferences(stack({ mappings: { lead_feed: { label: 'Lead feed' } } }))).toEqual([]); + }); + + it('a name no package declares is translation-target-unknown, at the named-item groups\' error', () => { + const findings = validateTranslationReferences(stack({ mappings: { lead_fede: { label: 'x' } } })); + expect(findings.map((f) => [f.rule, f.severity, f.path, f.where])).toEqual([ + [TRANSLATION_TARGET_UNKNOWN, 'error', 'translations[0].en.mappings.lead_fede', 'locale "en" · import mapping "lead_fede"'], + ]); + expect(findings[0].message).toContain('Did you mean "lead_feed"?'); + }); + + it('judges the group against its own collection — a report name under `mappings` is an orphan', () => { + const findings = validateTranslationReferences(stack( + { mappings: { opps_by_stage: { label: 'x' } } }, + { reports: [{ name: 'opps_by_stage', label: 'Opportunities by Stage', type: 'summary', dataset: 'pipeline', values: ['amount'] }] }, + )); + expect(findings.map((f) => f.path)).toEqual(['translations[0].en.mappings.opps_by_stage']); + }); + + it('resolves a name a sibling package of the artifact declares', () => { + const findings = validateTranslationReferences(stack( + { mappings: { contact_feed: { label: 'Contact feed' } } }, + { packages: [{ manifest: { mappings: [{ name: 'contact_feed', targetObject: 'contact', fieldMapping: [] }] } }] }, + )); + expect(findings).toEqual([]); + }); +}); + describe('validateTranslationReferences — hook refusals (#26170)', () => { const creditStack = { hooks: [ diff --git a/packages/lint/src/validate-translation-references.ts b/packages/lint/src/validate-translation-references.ts index 86ec21a9c0f..6e0b751a24a 100644 --- a/packages/lint/src/validate-translation-references.ts +++ b/packages/lint/src/validate-translation-references.ts @@ -186,6 +186,14 @@ * id, one group keyed `all`) is what the tree serves where a package authors * no book of that name, so its keys resolve too. * + * ── Import mappings ────────────────────────────────────────────────────── + * + * `mappings.` resolves against `Mapping.name`, the name + * `translateMapping` looks a served mapping up by, with the reports verdict: + * a name no package of this stack declares is an orphan, + * `translation-target-unknown` (`error`). The one leaf key below the name is + * the schema's `label` (strict). + * * ── Cross-package objects ──────────────────────────────────────────────── * * A stack legitimately translates objects it does not define — `sys_user`'s @@ -231,7 +239,7 @@ * is a key whose `COMPOSE_KEY_DISPOSITIONS` disposition puts it inside an * ADR-0130 D4 entry's assembled body: `objects` (#19064) plus `views`, * `pages`, `actions`, `apps`, `dashboards` and `flows` (#19349), - * `positions` and `permissions`, `reports`, and `books`. + * `positions` and `permissions`, `reports`, `books`, and `mappings`. * * ⚠️ `apps` reads BOTH that carrier and `navigationContributions`, and they * answer different questions — what a sibling DECLARES, and what this package @@ -591,6 +599,8 @@ interface Universe { permissionSets: Set; /** Report names (`Report.name`) a `reports.` key may name. */ reports: Set; + /** Import-mapping names (`Mapping.name`) a `mappings.` key may name. */ + mappings: Set; /** * Book name (`Book.name`) → the group `key`s a `books..groups.` * key may name; the implicit per-package book included (#26690). @@ -1780,6 +1790,8 @@ function buildUniverse(stack: AnyRec): Universe { const permissionSets = namesOf('permissions'); // `reports` carries disposition `concat` too, so a sibling's reports resolve. const reports = namesOf('reports'); + // `mappings` carries disposition `concat` too, so a sibling's mappings resolve. + const mappings = namesOf('mappings'); // ── Doc books: the names `books.` may name, and their group keys (#26690) ── // @@ -1821,6 +1833,7 @@ function buildUniverse(stack: AnyRec): Universe { positions, permissionSets, reports, + mappings, books, pages, }; @@ -2314,11 +2327,12 @@ export function validateTranslationReferences(stack: AnyRec): TranslationRefFind }); } - // ── positions. / permissions. / reports. ──────── + // ── positions. / permissions. / reports. / mappings. ── const namedItemGroups = [ { group: 'positions', noun: 'position', known: universe.positions, hint: "Match the key to a position's `name`, or drop it." }, { group: 'permissions', noun: 'permission set', known: universe.permissionSets, hint: "Match the key to a permission set's `name`, or drop it." }, { group: 'reports', noun: 'report', known: universe.reports, hint: "Match the key to a report's `name`, or drop it." }, + { group: 'mappings', noun: 'import mapping', known: universe.mappings, hint: "Match the key to an import mapping's `name`, or drop it." }, ] as const; for (const { group, noun, known, hint } of namedItemGroups) { for (const name of Object.keys(asRecord(rawData[group]))) { diff --git a/packages/metadata-protocol/src/protocol-discovery-and-bases.ts b/packages/metadata-protocol/src/protocol-discovery-and-bases.ts index fa6e75de9c2..2c4238cec23 100644 --- a/packages/metadata-protocol/src/protocol-discovery-and-bases.ts +++ b/packages/metadata-protocol/src/protocol-discovery-and-bases.ts @@ -15,7 +15,9 @@ * dataset, app and book packaged bases (`getPackagedPageBase`, * `getPackagedDatasetBase`, `getPackagedAppBase`, `getPackagedBookBase`), the * served-override reading of a served document (`servedOverrideBaseOf`) and the - * pair's own translations (`getPairTranslationBundle`). [#30504] The app base + * pair's own translations (`getPairTranslationBundle`). The import-mapping base + * (`getPackagedMappingBase`) joins them, the label `translateMapping` judges an + * override against. [#30504] The app base * carries the code layer's navigation contributions, folded once. * * A MOVE, not a redesign. `ProtocolDiscoveryAndBasesFacet` is a stateless facet over the host @@ -83,7 +85,7 @@ import type { ObjectStackProtocolImplementation } from './protocol.js'; * answers: the artifact item IS the packaged declaration for each (none has an * extension fold, unlike the object). */ -export type PackagedArtifactBaseType = 'dashboard' | 'view' | 'report' | 'page' | 'dataset' | 'app' | 'book'; +export type PackagedArtifactBaseType = 'dashboard' | 'view' | 'report' | 'page' | 'dataset' | 'app' | 'book' | 'mapping'; export class ProtocolDiscoveryAndBasesFacet { /** The body of `ObjectStackProtocolImplementation#getProjectId`; the method's docblock there is its contract. */ @@ -920,6 +922,11 @@ export class ProtocolDiscoveryAndBasesFacet { return host.packagedArtifactBase('book', name); } + /** The body of `ObjectStackProtocolImplementation#getPackagedMappingBase`; the method's docblock there is its contract. */ + static getPackagedMappingBase(host: Pick, name: string): unknown { + return host.packagedArtifactBase('mapping', name); + } + /** The body of `ObjectStackProtocolImplementation#servedOverrideBaseOf`; the method's docblock there is its contract. */ static servedOverrideBaseOf(type: string, document: unknown): string | undefined { return servedOverrideBaseOf(type, document); @@ -1056,7 +1063,8 @@ export class ProtocolDiscoveryAndBasesFacet { * The one body behind {@link getPackagedDashboardBase}, * {@link getPackagedViewBase}, {@link getPackagedReportBase} and * [#30062] {@link getPackagedPageBase}, {@link getPackagedDatasetBase}, - * {@link getPackagedAppBase} and {@link getPackagedBookBase}: + * {@link getPackagedAppBase}, {@link getPackagedBookBase} and + * {@link getPackagedMappingBase}: * {@link lookupArtifactItem}, and nothing wider, so only an item whose * `_packageId` marks a genuine code package answers, and an overlay * hydrated under the plain registry key never does. diff --git a/packages/metadata-protocol/src/protocol.ts b/packages/metadata-protocol/src/protocol.ts index ebfaff50fe1..08c65f0af79 100644 --- a/packages/metadata-protocol/src/protocol.ts +++ b/packages/metadata-protocol/src/protocol.ts @@ -2987,68 +2987,67 @@ export class ObjectStackProtocolImplementation implements } /** - * [#30062] The PACKAGED (code-layer) declaration of a PAGE — the page a - * code package ships, before a `.custom` pair's declared override replaces - * it (ADR-0146 D2). The page twin of {@link getPackagedDashboardBase}, - * answered the same way, and the fact `translatePage` - * (`@objectstack/spec/system`) compares against as its `packagedBase`: the - * i18n catalog (`pages.`) is the packaged translation of exactly - * this body, so it may only replace a string the served page still carries - * unchanged from it (ruling record 6631250894: a translation in the pair, - * then the override's own label, then the base's translation). - * - * Measured before this existed: a pair's override of the CRM's - * `crm_welcome` labelled `OVpage` was served, and a `zh-CN` reader got the - * base's `欢迎页`, because the translation of the served page had no base to - * compare with. + * [#30062] The PACKAGED (code-layer) declarations of a PAGE, DATASET, APP, + * BOOK and IMPORT MAPPING — the item a code package ships, before a + * `.custom` pair's declared override replaces it (ADR-0146 D2). One + * contract for the five accessors below: the page is the twin of + * {@link getPackagedDashboardBase}, the other four are twins of the page + * (and of each other), all answered the same way, and each is the fact its + * translator (`@objectstack/spec/system`) compares against as its + * `packagedBase`: the i18n catalog entry is the packaged translation of + * exactly this body, so it may only replace a string the served item still + * carries unchanged from it (ruling record 6631250894: a translation in the + * pair, then the override's own label, then the base's translation). + * + * - `getPackagedPageBase`: `translatePage`, `pages.`. Measured before + * this existed: a pair's override of the CRM's `crm_welcome` labelled + * `OVpage` was served, and a `zh-CN` reader got the base's `欢迎页`, + * because the translation of the served page had no base to compare + * with. A page has no extension fold, so the artifact item IS the + * packaged declaration. + * - `getPackagedDatasetBase`: `translateDataset`, each string of + * `datasets.` (label, description, dimension and measure labels), + * for the page's reason: a pair's dataset override kept the base's + * translated label and measure labels over its own. + * - `getPackagedAppBase`: `translateApp`, each string of `apps.` + * (label, description and navigation labels, a node judged against the + * base's node of the same `id`). + * - `getPackagedBookBase`: `translateBook`, each string of `books.` + * (label, description and group labels, a group judged against the + * base's group of the same `key`). + * - `getPackagedMappingBase` (#34939): `translateMapping`, the served + * label only (`mappings..label`). * * Shadow-immune for the dashboard's reason: the override is served from its - * row, never as the artifact, so the body returned is the base's own. A - * page has no extension fold, so the artifact item IS the packaged - * declaration. Returns `undefined` for a page no code package ships, an - * unknown or empty name, and a registry double without the lookup — "no - * packaged baseline", read by the translator as the catalog applying - * unchanged. + * row, never as the artifact, so the body returned is the base's own. Each + * returns `undefined` for an item no code package ships, an unknown or + * empty name, and a registry double without the lookup — "no packaged + * baseline", read by the translator as the catalog applying unchanged. */ getPackagedPageBase(name: string): unknown { return ProtocolDiscoveryAndBasesFacet.getPackagedPageBase(protocolHost(this), name); } - /** - * [#30062] The PACKAGED (code-layer) declaration of a DATASET, the fact - * `translateDataset` compares each string against (`datasets.`: its - * label, description, dimension and measure labels). The dataset twin of - * {@link getPackagedPageBase}, answered the same way and for the same - * reason: a pair's dataset override kept the base's translated label and - * measure labels over its own. Returns `undefined` on the same - * uncertainties. - */ + /** Contract: the shared docblock on {@link getPackagedPageBase}. */ getPackagedDatasetBase(name: string): unknown { return ProtocolDiscoveryAndBasesFacet.getPackagedDatasetBase(protocolHost(this), name); } - /** - * [#30062] The PACKAGED (code-layer) declaration of an APP, the fact - * `translateApp` compares each string against (`apps.`: its label, - * description and navigation labels, a node judged against the base's node - * of the same `id`). The app twin of {@link getPackagedPageBase}, answered - * the same way. Returns `undefined` on the same uncertainties. - */ + /** Contract: the shared docblock on {@link getPackagedPageBase}. */ getPackagedAppBase(name: string): unknown { return ProtocolDiscoveryAndBasesFacet.getPackagedAppBase(protocolHost(this), name); } - /** - * [#30062] The PACKAGED (code-layer) declaration of a BOOK, the fact - * `translateBook` compares each string against (`books.`: its label, - * description and group labels, a group judged against the base's group of - * the same `key`). The book twin of {@link getPackagedPageBase}, answered - * the same way. Returns `undefined` on the same uncertainties. - */ + /** Contract: the shared docblock on {@link getPackagedPageBase}. */ getPackagedBookBase(name: string): unknown { return ProtocolDiscoveryAndBasesFacet.getPackagedBookBase(protocolHost(this), name); } + /** Contract: the shared docblock on {@link getPackagedPageBase}. */ + getPackagedMappingBase(name: string): unknown { + return ProtocolDiscoveryAndBasesFacet.getPackagedMappingBase(protocolHost(this), name); + } + /** * [#30062, ADR-0146 D2] The base package a SERVED metadata document is the * declared override of, or `undefined` when it is none — read off the diff --git a/packages/objectql/src/protocol-custom-override-bare-slot-envelope.test.ts b/packages/objectql/src/protocol-custom-override-bare-slot-envelope.test.ts index 8369474f7d3..a237dc490d7 100644 --- a/packages/objectql/src/protocol-custom-override-bare-slot-envelope.test.ts +++ b/packages/objectql/src/protocol-custom-override-bare-slot-envelope.test.ts @@ -610,9 +610,9 @@ async function boot2(environmentId: string | undefined, type: string, name: stri * hydration, the pair through its ensure door, the override through Studio's * draft save and publish): * - * - the PACKAGED base of a page, dataset, app and book + * - the PACKAGED base of a page, dataset, app, book and import mapping * (`getPackagedPageBase`, `getPackagedDatasetBase`, `getPackagedAppBase`, - * `getPackagedBookBase`) answers the base's own item while the pair's + * `getPackagedBookBase`, `getPackagedMappingBase`) answers the base's own item while the pair's * override is served, at once and after a restart, with and without a * metadata service — never the override it is compared against; * - the served override names its base (`servedOverrideBaseOf`), the base's @@ -624,10 +624,10 @@ async function boot2(environmentId: string | undefined, type: string, name: stri const PAIR_TRANSLATION = 'showcase_custom_zh_cn'; /** The `zh-CN` text each type's catalog group carries, keyed by the item's name. */ const zhGroup = (type: string, name: string, label: string): Record => { - const group = ({ page: 'pages', app: 'apps', dataset: 'datasets', book: 'books' } as Record)[type]; + const group = ({ page: 'pages', app: 'apps', dataset: 'datasets', book: 'books', mapping: 'mappings' } as Record)[type]; return { [group]: { [name]: { label } } }; }; -const LABEL_ORDER_TYPES = SEALED_TYPES.filter((t) => ['page', 'app', 'dataset', 'book'].includes(t.type)); +const LABEL_ORDER_TYPES = SEALED_TYPES.filter((t) => ['page', 'app', 'dataset', 'book', 'mapping'].includes(t.type)); const accessorOf = (type: string): string => `getPackaged${type[0].toUpperCase()}${type.slice(1)}Base`; describe('[#30062] a declared override\'s label order: the packaged base and the pair\'s own translations, on a real boot', () => { diff --git a/packages/rest/src/meta-dashboard-view-i18n-explicit-override.test.ts b/packages/rest/src/meta-dashboard-view-i18n-explicit-override.test.ts index cb6ed5fb721..f1d1282e04b 100644 --- a/packages/rest/src/meta-dashboard-view-i18n-explicit-override.test.ts +++ b/packages/rest/src/meta-dashboard-view-i18n-explicit-override.test.ts @@ -300,6 +300,8 @@ describe('#20730 §1 packagedObjectBaseOf — one per-type packaged-base resolve getPackagedDatasetBase: vi.fn((name: string) => ({ kind: 'dataset', name })), getPackagedAppBase: vi.fn((name: string) => ({ kind: 'app', name })), getPackagedBookBase: vi.fn((name: string) => ({ kind: 'book', name })), + // An import mapping is an ADR-0146 D2 listed overridable type as well. + getPackagedMappingBase: vi.fn((name: string) => ({ kind: 'mapping', name })), }); it('asks each type its own accessor, handing the served name through unchanged', () => { @@ -319,7 +321,8 @@ describe('#20730 §1 packagedObjectBaseOf — one per-type packaged-base resolve expect(packagedObjectBaseOf(p, 'dataset', 'opportunity_metrics')).toEqual({ kind: 'dataset', name: 'opportunity_metrics' }); expect(packagedObjectBaseOf(p, 'app', 'crm')).toEqual({ kind: 'app', name: 'crm' }); expect(packagedObjectBaseOf(p, 'book', 'crm_manual')).toEqual({ kind: 'book', name: 'crm_manual' }); - for (const accessor of ['getPackagedPageBase', 'getPackagedDatasetBase', 'getPackagedAppBase', 'getPackagedBookBase'] as const) { + expect(packagedObjectBaseOf(p, 'mapping', 'crm_lead_feed')).toEqual({ kind: 'mapping', name: 'crm_lead_feed' }); + for (const accessor of ['getPackagedPageBase', 'getPackagedDatasetBase', 'getPackagedAppBase', 'getPackagedBookBase', 'getPackagedMappingBase'] as const) { expect(p[accessor], accessor).toHaveBeenCalledTimes(1); } }); @@ -443,7 +446,8 @@ describe('#25788 §4 report — a published overlay on a packaged report is what * * - `packagedBase` — the BASE's item, for a page, a dataset, an app and a * book too (`getPackagedPageBase`, `getPackagedDatasetBase`, - * `getPackagedAppBase`, `getPackagedBookBase`), as the object, dashboard, + * `getPackagedAppBase`, `getPackagedBookBase`), and an import mapping + * (`getPackagedMappingBase`), as the object, dashboard, * view and report already had it; * - `pairBundle` — the translations the pair ships itself * (`servedOverrideBaseOf` + `getPairTranslationBundle`), for every served @@ -467,7 +471,7 @@ const PAIR_PKG = `${SHOWCASE_PKG}.custom`; const OVERRIDE_DECLARATION = { package: SHOWCASE_PKG, basedOn: '1.0.0' }; interface PrecedenceType { - readonly type: 'page' | 'dataset' | 'app' | 'book' | 'view'; + readonly type: 'page' | 'dataset' | 'app' | 'book' | 'mapping' | 'view'; readonly name: string; /** The base's item, as the code package ships it. */ readonly shipped: () => Record; @@ -501,6 +505,12 @@ const PRECEDENCE_TYPES: readonly PrecedenceType[] = [ shipped: () => ({ name: 'crm_manual', label: 'Manual', groups: [{ key: 'start', label: 'Start', pages: [] }] }), catalog: (label) => ({ books: { crm_manual: { label } } }), }, + // A named import mapping: the wizard's saved-mapping selector lists `GET /meta/mapping`. + { + type: 'mapping', name: 'crm_lead_feed', shippedZh: '线索导入', + shipped: () => ({ name: 'crm_lead_feed', label: 'Lead feed', targetObject: OBJ, sourceFormat: 'csv', mode: 'insert', fieldMapping: [{ source: 'Subject', target: 'subject' }] }), + catalog: (label) => ({ mappings: { crm_lead_feed: { label } } }), + }, // An existing type, for the pair's rank: the base was always handed over, the pair's translation never. { type: 'view', name: VIEW, shippedZh: '进行中', diff --git a/packages/rest/src/meta-item-read-gate.ts b/packages/rest/src/meta-item-read-gate.ts index 449c355dcd0..e52e82e503c 100644 --- a/packages/rest/src/meta-item-read-gate.ts +++ b/packages/rest/src/meta-item-read-gate.ts @@ -3323,7 +3323,9 @@ export function metaTranslateOptions( * ADR-0131 D6), but a `.custom` pair's declared override replaces the * base's item on every read (ADR-0146 D2), so the served document can * differ from the one the catalog translates (`getPackagedPageBase`, - * `getPackagedDatasetBase`, `getPackagedAppBase`, `getPackagedBookBase`). + * `getPackagedDatasetBase`, `getPackagedAppBase`, `getPackagedBookBase`); + * an import `mapping` is an ADR-0146 D2 listed overridable type as well + * (`getPackagedMappingBase`). * The label order the base feeds is ruling record 6631250894's: a * translation in the pair ({@link pairTranslationBundleOf}), then the * override's own label, then the base's translation. @@ -3344,6 +3346,7 @@ const PACKAGED_BASE_ACCESSORS: ReadonlyMap = new Map = new MapBase(name)`. + * `getPackagedReportBase(name)`, and [#30062] a `page`, `dataset`, `app`, + * `book` or `mapping` its own `getPackagedBase(name)`. * * `undefined` on every uncertainty — a type with no row, an empty name, a * protocol without the accessor (they are server-only extensions, so diff --git a/packages/runtime/src/domains/meta-list-projection-parity.test.ts b/packages/runtime/src/domains/meta-list-projection-parity.test.ts index 3f5dfab6b32..e9b6662f7f1 100644 --- a/packages/runtime/src/domains/meta-list-projection-parity.test.ts +++ b/packages/runtime/src/domains/meta-list-projection-parity.test.ts @@ -167,6 +167,8 @@ const STORE: Record = { page: [{ name: 'home', label: 'Home', type: 'app' }], action: [{ name: 'close_case', label: 'Close case', objectName: 'case', type: 'script' }], dataset: [{ name: 'pipeline', label: 'Pipeline', object: 'opportunity' }], + // A named import mapping, offered by label in the import wizard. + mapping: [{ name: 'lead_feed', label: 'Lead feed', targetObject: 'lead', sourceFormat: 'csv', mode: 'insert', fieldMapping: [{ source: 'Company', target: 'company' }] }], picklist: [{ name: 'industry', label: 'Industry', options: [{ label: 'Technology', value: 'technology' }] }], flow: [{ name: 'on_lead', label: 'On lead', type: 'autolaunched' }], // [#25333] The `?include=grants` step describes each position. @@ -230,6 +232,8 @@ const BUNDLE: Record = { reports: { opps_by_stage: { label: '各阶段商机' } }, // [#26690] A doc book's title and section titles. books: { help_center: { label: '帮助中心', groups: { start: { label: '开始' } } } }, + // A named import mapping's label. + mappings: { lead_feed: { label: '线索导入' } }, }, }; @@ -567,7 +571,7 @@ const PARAM_AXIS = new Set(PARAM_PROBES.map((p) => p.param).filter((p): p is str const TYPE_CELLS: readonly string[] = [ 'app', 'apps', 'view', 'views', 'doc', 'docs', 'book', 'books', 'api', 'apis', 'object', 'objects', 'dashboard', 'dashboards', 'page', 'action', 'dataset', 'picklist', 'flow', - 'position', 'positions', 'permission', 'permissions', 'report', 'reports', + 'position', 'positions', 'permission', 'permissions', 'report', 'reports', 'mapping', 'mappings', // [#20408] A segment that names no metadata type: `RestServer` refuses it // (`refuseUnknownMetaListType`) rather than listing an empty collection. 'totally_invented_type', @@ -763,6 +767,11 @@ describe('[#20320] row A: the reference moves — each probe changes RestServer\ expect([zhHelp?.label, zhHelp?.groups?.map((g: any) => g.label)]).toEqual(['帮助中心', ['开始']]); const enHelp = (await read('/meta/book', {}, { 'accept-language': 'en-US' })).items?.find((b: any) => b.name === 'help_center'); expect([enHelp?.label, enHelp?.groups?.map((g: any) => g.label)]).toEqual(['Help Centre', ['Start']]); + // So is a named import mapping — the list the import wizard's saved-mapping selector reads. + const zhMappings = await read('/meta/mappings', {}, { 'accept-language': 'zh-CN' }); + expect(zhMappings.items?.find((m: any) => m.name === 'lead_feed')?.label).toBe('线索导入'); + const enMappings = await read('/meta/mapping', {}, { 'accept-language': 'en-US' }); + expect(enMappings.items?.find((m: any) => m.name === 'lead_feed')?.label).toBe('Lead feed'); }); }); @@ -936,6 +945,7 @@ const ITEM_CELLS: readonly string[] = [ '/meta/dashboard/ops', '/meta/dashboards/ops', '/meta/page/home', '/meta/action/close_case', '/meta/dataset/pipeline', '/meta/picklist/industry', '/meta/flow/on_lead', '/meta/api/crm_served', '/meta/position/sales_rep', '/meta/permission/crm_sales_user', '/meta/report/opps_by_stage', + '/meta/mapping/lead_feed', '/meta/mappings/lead_feed', ]; const ITEM_TYPE_AXIS = new Set(ITEM_CELLS.map((c) => singular(c.split('/')[2]))); const ITEM_CALLERS = ['holder', 'non-holder', 'builder', 'author'] as const satisfies readonly CallerName[]; @@ -1087,6 +1097,7 @@ describe('[#20408] the item read: the reference moves — each probe changes Res expect((await read('/meta/permission/crm_sales_user', {}, { 'accept-language': 'zh-CN' })).item?.label).toBe('销售用户'); expect((await read('/meta/report/opps_by_stage', {}, { 'accept-language': 'zh-CN' })).item?.label).toBe('各阶段商机'); expect((await read('/meta/book/help_center', {}, { 'accept-language': 'zh-CN' })).item?.groups?.[0]?.label).toBe('开始'); + expect((await read('/meta/mapping/lead_feed', {}, { 'accept-language': 'zh-CN' })).item?.label).toBe('线索导入'); const zhDoc = await read('/meta/doc/crm_intro', { locale: 'zh-CN' }); expect(zhDoc.item?.label).toBe('入门'); expect(text(zhDoc)).not.toContain('"translations"'); diff --git a/packages/spec/api-surface/system.json b/packages/spec/api-surface/system.json index ba4b300ff03..e44e9dbd6a7 100644 --- a/packages/spec/api-surface/system.json +++ b/packages/spec/api-surface/system.json @@ -350,6 +350,7 @@ "METADATA_FORM_REGISTRY (const)", "MIGRATION_JOURNAL_KINDS (const)", "MIGRATION_JOURNAL_OBJECT (const)", + "MappingLike (interface)", "MaskingVisibilityRule (type)", "MaskingVisibilityRuleParsed (type)", "MaskingVisibilityRuleSchema (const)", @@ -939,6 +940,7 @@ "translateDashboard (function)", "translateDataset (function)", "translateFlow (function)", + "translateMapping (function)", "translateMetadataDocument (function)", "translateObject (function)", "translatePage (function)", diff --git a/packages/spec/authorable-surface/system.json b/packages/spec/authorable-surface/system.json index af65c7d8aec..cf1759853e0 100644 --- a/packages/spec/authorable-surface/system.json +++ b/packages/spec/authorable-surface/system.json @@ -922,6 +922,7 @@ "system/PlatformTranslationData:flows", "system/PlatformTranslationData:globalActions", "system/PlatformTranslationData:hooks", + "system/PlatformTranslationData:mappings", "system/PlatformTranslationData:messages", "system/PlatformTranslationData:metadataForms", "system/PlatformTranslationData:objects", @@ -1062,6 +1063,7 @@ "system/ServedTranslationData:flows", "system/ServedTranslationData:globalActions", "system/ServedTranslationData:hooks", + "system/ServedTranslationData:mappings", "system/ServedTranslationData:messages", "system/ServedTranslationData:objects", "system/ServedTranslationData:pages", @@ -1371,6 +1373,7 @@ "system/TranslationData:flows", "system/TranslationData:globalActions", "system/TranslationData:hooks", + "system/TranslationData:mappings", "system/TranslationData:messages", "system/TranslationData:metadataForms", "system/TranslationData:objects", @@ -1403,6 +1406,7 @@ "system/TranslationItem:hooks", "system/TranslationItem:label", "system/TranslationItem:locale", + "system/TranslationItem:mappings", "system/TranslationItem:messages", "system/TranslationItem:metadataForms", "system/TranslationItem:name", diff --git a/packages/spec/export-origins/system.json b/packages/spec/export-origins/system.json index 3563b693b49..281d89f8640 100644 --- a/packages/spec/export-origins/system.json +++ b/packages/spec/export-origins/system.json @@ -337,6 +337,7 @@ "METADATA_FORM_REGISTRY": "src/system/metadata-form-registry.ts#METADATA_FORM_REGISTRY (const)", "MIGRATION_JOURNAL_KINDS": "src/system/migration.zod.ts#MIGRATION_JOURNAL_KINDS (const)", "MIGRATION_JOURNAL_OBJECT": "src/system/migration.zod.ts#MIGRATION_JOURNAL_OBJECT (const)", + "MappingLike": "src/system/i18n-resolver.ts#MappingLike (interface)", "MaskingVisibilityRule": "src/system/security-context.zod.ts#MaskingVisibilityRule (type)", "MaskingVisibilityRuleParsed": "src/system/security-context.zod.ts#MaskingVisibilityRuleParsed (type)", "MaskingVisibilityRuleSchema": "src/system/security-context.zod.ts#MaskingVisibilityRuleSchema (const)", @@ -899,6 +900,7 @@ "translateDashboard": "src/system/i18n-resolver.ts#translateDashboard (function)", "translateDataset": "src/system/i18n-resolver.ts#translateDataset (function)", "translateFlow": "src/system/i18n-resolver.ts#translateFlow (function)", + "translateMapping": "src/system/i18n-resolver.ts#translateMapping (function)", "translateMetadataDocument": "src/system/i18n-resolver.ts#translateMetadataDocument (function)", "translateObject": "src/system/i18n-resolver.ts#translateObject (function)", "translatePage": "src/system/i18n-resolver.ts#translatePage (function)", diff --git a/packages/spec/liveness/state-counts/translation.md b/packages/spec/liveness/state-counts/translation.md index ed523cd674d..60bf69c6bd3 100644 --- a/packages/spec/liveness/state-counts/translation.md +++ b/packages/spec/liveness/state-counts/translation.md @@ -12,4 +12,4 @@ committed anywhere: `check:liveness` sums the shards when it reads them. | Type | live | exp | elsewhere | dead | planned | classified | |---|---|---|---|---|---|---| -| `translation` | 46 | 0 | 0 | 0 | 2 | 48 | +| `translation` | 47 | 0 | 0 | 0 | 2 | 49 | diff --git a/packages/spec/liveness/translation.json b/packages/spec/liveness/translation.json index 2da338a1e24..66e10e7c2fe 100644 --- a/packages/spec/liveness/translation.json +++ b/packages/spec/liveness/translation.json @@ -388,6 +388,20 @@ } } }, + "mappings": { + "status": "live", + "verifiedAt": "2026-11-17", + "evidence": "packages/spec/src/system/i18n-resolver.ts#translateMapping (`mappings..label`, registered in METADATA_DOCUMENT_TRANSLATORS); packages/rest/src/meta-item-read-gate.ts#translateMetaList (the /meta list read that applies it per request locale)", + "note": "Seeded LIVE with its reader in the same change (the datasets precedent): a served `mapping` document is localized at the REST boundary, list and item, and `GET /meta/mapping` is what the console's import wizard offers by label in its saved-mapping selector. The face stops at the one string a mapping authors for a reader; its `fieldMapping` is column and field names.", + "children": { + "label": { + "status": "live", + "verifiedAt": "2026-11-17", + "evidence": "packages/spec/src/system/i18n-resolver.ts#lookupMappingLabel (`mappings..label`, read by translateMapping)", + "note": "Overlays the served mapping's own `label`." + } + } + }, "metadataForms": { "status": "live", "verifiedAt": "2026-08-28", diff --git a/packages/spec/src/data/mapping.zod.ts b/packages/spec/src/data/mapping.zod.ts index 8a5311cdef9..e313c815d22 100644 --- a/packages/spec/src/data/mapping.zod.ts +++ b/packages/spec/src/data/mapping.zod.ts @@ -409,7 +409,7 @@ export const MappingSchema = lazySchema(() => strictObject({ }, { /** Identity */ name: SnakeCaseIdentifierSchema.describe('Mapping unique name (lowercase snake_case)'), - label: z.string().optional(), + label: z.string().optional().describe('Display label, shown where the mapping is offered by name (the import wizard); translated per locale at `mappings..label` in the translation bundle'), /** Scope */ sourceFormat: z.enum(['csv', 'json', 'xml', 'sql']).default('csv'), diff --git a/packages/spec/src/system/i18n-mapping.test.ts b/packages/spec/src/system/i18n-mapping.test.ts new file mode 100644 index 00000000000..1ca7c8dff27 --- /dev/null +++ b/packages/spec/src/system/i18n-mapping.test.ts @@ -0,0 +1,110 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// `mappings..label` — a named import mapping's translation group, and +// the translator that overlays it on the served `mapping` document. +// +// Before this group existed a shipped import mapping showed its authored +// label in every locale: the console's import wizard offers mappings by label +// (`GET /meta/mapping`), the label is a plain string on the mapping, and the +// bundle had no key for it. + +import { describe, it, expect } from 'vitest'; +import { + TranslationDataSchema, + TranslationItemSchema, + PlatformTranslationDataSchema, + ServedTranslationDataSchema, + type TranslationBundle, +} from './translation.zod'; +import { translateMetadataDocument, translateMapping, TRANSLATABLE_METADATA_TYPES } from './i18n-resolver'; +// The fixture is PARSED by the authoring schema rather than hand-shaped, so a +// translator reading a member the schema does not carry cannot pass here. +import { MappingSchema } from '../data/mapping.zod'; + +const mapping = () => MappingSchema.parse({ + name: 'weekly_supply_import', + label: 'Weekly Supply Import (CSV)', + sourceFormat: 'csv', + targetObject: 'supply_plan', + fieldMapping: [ + { source: 'Week', target: 'supply_week' }, + { source: 'Reserved', target: 'domestic_reserved_qty' }, + ], +}) as any; + +const bundle: TranslationBundle = { + 'zh-CN': { mappings: { weekly_supply_import: { label: '每周供应导入(CSV)' } } }, +}; + +describe('TranslationDataSchema — mappings', () => { + it('opens at every door — bundle entry, platform bundle, served document and registered item', () => { + expect(TranslationDataSchema.safeParse(bundle['zh-CN']).success).toBe(true); + expect(PlatformTranslationDataSchema.safeParse(bundle['zh-CN']).success).toBe(true); + expect(ServedTranslationDataSchema.safeParse(bundle['zh-CN']).success).toBe(true); + expect(TranslationItemSchema.safeParse({ locale: 'zh-CN', ...bundle['zh-CN'] }).success).toBe(true); + }); + + it('closes the face at the mapping\'s `label`', () => { + const result = TranslationDataSchema.safeParse({ mappings: { weekly_supply_import: { icon: 'csv' } } }); + expect(result.success).toBe(false); + expect(result.error!.issues.map((i) => i.code)).toContain('unrecognized_keys'); + }); + + it('renames the singular and the label\'s aliases onto the declared keys', () => { + expect(() => TranslationDataSchema.parse({ mapping: { m: { label: 'x' } } })).toThrow(/mappings/); + expect(() => TranslationDataSchema.parse({ mappings: { m: { title: 'x' } } })).toThrow(/label/); + expect(() => TranslationItemSchema.parse({ locale: 'zh-CN', mapping: { m: { label: 'x' } } })).toThrow(/mappings/); + }); + + it('names why `description` and `fieldMapping` have no key, rather than suggesting one', () => { + const description = TranslationDataSchema.safeParse({ mappings: { m: { description: 'x' } } }); + expect(description.success).toBe(false); + expect(JSON.stringify(description.error!.issues)).toContain('declares no `description`'); + const fields = TranslationDataSchema.safeParse({ mappings: { m: { fieldMapping: {} } } }); + expect(fields.success).toBe(false); + expect(JSON.stringify(fields.error!.issues)).toContain('objects..fields..label'); + }); +}); + +describe('translateMapping', () => { + it('is registered in the dispatch table, so the REST boundary follows', () => { + // `TRANSLATABLE_METADATA_TYPES` is DERIVED from the dispatch table and + // `@objectstack/rest` reads it: `GET /meta/mapping` (list and item) is + // localized with no further wiring. + expect(TRANSLATABLE_METADATA_TYPES.has('mapping')).toBe(true); + }); + + it('a zh-CN reader gets the translated label; identity and field mapping ride through', () => { + const doc = mapping(); + const out = translateMetadataDocument('mapping', doc, bundle, { locale: 'zh-CN' }) as any; + expect(out.label).toBe('每周供应导入(CSV)'); + expect(out.name).toBe('weekly_supply_import'); + expect(out.fieldMapping).toBe(doc.fieldMapping); + }); + + it('an en-US reader is unchanged — the same reference, the authored label', () => { + const doc = mapping(); + expect(translateMapping(doc, bundle, { locale: 'en-US' })).toBe(doc); + expect(translateMapping(doc, undefined, { locale: 'zh-CN' })).toBe(doc); + }); + + it('reads only its own mapping\'s entry, and applies the BCP-47 ladder and the fallback chain', () => { + const other = MappingSchema.parse({ name: 'other_import', label: 'Other', targetObject: 'supply_plan', fieldMapping: [] }) as any; + expect(translateMapping(other, bundle, { locale: 'zh-CN' })).toBe(other); + expect((translateMapping(mapping(), bundle, { locale: 'zh' }) as any).label).toBe('每周供应导入(CSV)'); + expect((translateMapping(mapping(), bundle, { locale: 'fr-FR', fallbackChain: ['zh-CN'] }) as any).label).toBe('每周供应导入(CSV)'); + }); + + it('an empty translated label is no translation — the authored label stands', () => { + const doc = mapping(); + const empty: TranslationBundle = { 'zh-CN': { mappings: { weekly_supply_import: { label: '' } } } }; + expect(translateMapping(doc, empty, { locale: 'zh-CN' })).toBe(doc); + }); + + it('does not mutate the input', () => { + const doc = mapping(); + const before = JSON.parse(JSON.stringify(doc)); + translateMapping(doc, bundle, { locale: 'zh-CN' }); + expect(doc).toEqual(before); + }); +}); diff --git a/packages/spec/src/system/i18n-resolver.test.ts b/packages/spec/src/system/i18n-resolver.test.ts index 217bdc8bd07..858e9ecbcad 100644 --- a/packages/spec/src/system/i18n-resolver.test.ts +++ b/packages/spec/src/system/i18n-resolver.test.ts @@ -6462,6 +6462,7 @@ describe('resolveMetadataFormSchemaTitles — bundle labels overlaid as JSON Sch import { type TranslateDocumentOptions } from './i18n-resolver'; import { ReportSchema } from '../ui/report.zod'; import { BookSchema } from './book.zod'; +import { MappingSchema } from '../data/mapping.zod'; describe("label precedence on an overridden item — the pair's translation, then the override's label, then the base's translation (ADR-0146 D2)", () => { /** One translatable string of a served document, and the bundle address that translates it. */ @@ -6636,10 +6637,23 @@ describe("label precedence on an overridden item — the pair's translation, the ['books', 'crm_manual', 'groups', 'start', 'label'], '快速上手'), ], }, + // An import mapping is an ADR-0146 D2 listed overridable type too, and its + // one translatable string is its label. + mapping: { + base: () => MappingSchema.parse({ + name: 'crm_lead_feed', + label: 'Lead feed', + targetObject: 'crm_lead', + fieldMapping: [{ source: 'Company', target: 'company' }], + }), + slots: [ + slot('label', (d) => d.label, (d, t) => { d.label = t; }, ['mappings', 'crm_lead_feed', 'label'], '线索导入'), + ], + }, }; - it('covers every document translator the ruling names — all eight types', () => { - expect(Object.keys(CASES).sort()).toEqual(['app', 'book', 'dashboard', 'dataset', 'object', 'page', 'report', 'view']); + it('covers every document translator the ruling names — all nine types', () => { + expect(Object.keys(CASES).sort()).toEqual(['app', 'book', 'dashboard', 'dataset', 'mapping', 'object', 'page', 'report', 'view']); for (const type of Object.keys(CASES)) expect(TRANSLATABLE_METADATA_TYPES.has(type), type).toBe(true); }); diff --git a/packages/spec/src/system/i18n-resolver.ts b/packages/spec/src/system/i18n-resolver.ts index aa29ff7e6d5..e88a00354ff 100644 --- a/packages/spec/src/system/i18n-resolver.ts +++ b/packages/spec/src/system/i18n-resolver.ts @@ -2043,6 +2043,10 @@ const METADATA_DOCUMENT_TRANSLATORS: Record< // its sidebar from `GET /meta/book`, and the tree route translates the book // it resolves through this same table (`createMetaBookTreeAnswer`). book: translateBook, + // A named import mapping's label: the console's import wizard offers each + // mapping by label from `GET /meta/mapping`, so registering here is the + // whole wiring. + mapping: translateMapping, }; /** @@ -2977,6 +2981,70 @@ export function translateBook( }; } +// ──────────────────────────────────────────────────────────────────────────── +// Import mapping resolver (label) +// ──────────────────────────────────────────────────────────────────────────── + +/** Minimal import-mapping shape consumed by {@link translateMapping}. */ +export interface MappingLike { + name: string; + label?: string; + [key: string]: any; +} + +function lookupMappingLabel( + bundle: TranslationBundle | undefined, + mappingName: string, + opts?: ResolveOptions, +): string | undefined { + if (!bundle) return undefined; + for (const code of localeChain(opts)) { + const candidate = pickData(bundle, code)?.mappings?.[mappingName]?.label; + if (typeof candidate === 'string' && candidate.length > 0) return candidate; + } + return undefined; +} + +/** + * Apply the active locale to an import-mapping metadata document — its + * `label` against `mappings..label`. The input document is not mutated; + * it comes back as the same reference when the bundle carries no label for + * it, and then the authored label stands. + * + * Registered in {@link METADATA_DOCUMENT_TRANSLATORS}, so the REST boundary + * localizes every served mapping (`GET /meta/mapping`, list and item) — the + * list the console's import wizard offers by name in its saved-mapping + * selector. A mapping's `fieldMapping` is not copy (column names and field + * names) and is left alone. + * + * ## An override's own label — ADR-0146 D2 + * + * A mapping is overridable from its base's paired `.custom` package, and the + * catalog translates the BASE's label. So the label follows + * {@link labelCatalogs}' order, judged against + * {@link TranslateDocumentOptions.packagedBase} by + * {@link valueOverridesPackagedBase}: a label the override changed reads only + * the pair's translations and otherwise keeps its own text; a label it left + * alone takes the pair's translation, then the base's. No base supplied: the + * catalog applies. + */ +export function translateMapping( + doc: T, + bundle: TranslationBundle | undefined, + opts?: TranslateDocumentOptions, +): T { + if (!doc || typeof doc !== 'object') return doc; + const mappingName = doc.name; + const catalogs = labelCatalogs(bundle, opts); + if (typeof mappingName !== 'string' || mappingName.length === 0 || !catalogs.unchanged) return doc; + const base = asRecord(opts?.packagedBase); + const label = lookupMappingLabel( + catalogFor(catalogs, valueOverridesPackagedBase(base, 'label', doc.label)), mappingName, opts, + ); + if (label === undefined) return doc; + return { ...doc, label }; +} + // ──────────────────────────────────────────────────────────────────────────── // Report metadata resolver (label + description) // ──────────────────────────────────────────────────────────────────────────── diff --git a/packages/spec/src/system/translation.zod.ts b/packages/spec/src/system/translation.zod.ts index ca7213ff465..40a7c3b6509 100644 --- a/packages/spec/src/system/translation.zod.ts +++ b/packages/spec/src/system/translation.zod.ts @@ -1036,10 +1036,10 @@ const PER_APP_SETTINGS_PLATFORM_ONLY = + '(`@objectstack/service-settings`\'s `settingsBuiltinTranslations`, typed ' + '`PlatformTranslationData`); a key it does not translate falls back to the manifest\'s own ' + 'literal, so correct it there rather than filling the gap from an application. For an ' - + 'application\'s own copy use the sixteen groups this bundle does declare, in the order it ' + + 'application\'s own copy use the seventeen groups this bundle does declare, in the order it ' + "declares them — 'objects', 'picklists', 'apps', 'messages', 'globalActions', 'dashboards', " + "'datasets', 'reports', 'pages', 'flows', 'hooks', 'positions', 'permissions', 'books', " - + "'metadataForms', 'settingsCommon'. " + + "'mappings', 'metadataForms', 'settingsCommon'. " + "Note the last one: 'settingsCommon' IS " + 'on this face, so the Settings UI shell strings an application may translate (the source ' + 'badges, under `settingsCommon.sourceLabels`) are NOT what is being refused here — only the ' @@ -1081,7 +1081,7 @@ const ITEM_SETTINGS_PLATFORM_ONLY = + '(`@objectstack/service-settings`\'s `settingsBuiltinTranslations`, typed ' + '`PlatformTranslationData`); a key it does not translate falls back to the manifest\'s own ' + 'literal, so correct it there rather than overriding it from an application. For an ' - + 'application\'s own copy use the groups this item does declare — the same sixteen a per-app ' + + 'application\'s own copy use the groups this item does declare — the same seventeen a per-app ' + "bundle declares, 'settingsCommon' among them: the Settings UI shell strings an application " + 'may translate (the source badges, under `settingsCommon.sourceLabels`) are NOT what is being ' + "refused here — only the per-namespace manifest copy under 'settings' is. " @@ -1120,12 +1120,12 @@ const ITEM_TRANSLATION_KEY_GUIDANCE: Record = { */ /** * The translation groups an APPLICATION may author, as a shape rather than a - * schema. Sixteen groups — the seventeenth, `settings`, is platform-only and lives in + * schema. Seventeen groups — the eighteenth, `settings`, is platform-only and lives in * {@link platformSettingsShape}. * * Three schemas need exactly these keys: {@link TranslationDataSchema} (one - * entry of a per-app file-authored bundle — these sixteen and no more), - * {@link PlatformTranslationDataSchema} (these sixteen plus `settings`) and + * entry of a per-app file-authored bundle — these seventeen and no more), + * {@link PlatformTranslationDataSchema} (these seventeen plus `settings`) and * {@link TranslationItemSchema} (the registered `translation` metadata type — * the per-app face plus `locale`, its identity keys and the ADR-0010 * envelope; it carried the platform face's `settings` too until #19620). The item used to @@ -2323,6 +2323,33 @@ const appTranslationDataShape = () => ({ })).optional().describe('Group (section) translations keyed by the group `key`'), })).optional().describe('Doc-book translations keyed by book name'), + /** + * Import-mapping translations keyed by mapping name (`Mapping.name`, + * `data/mapping.zod.ts`, the stack's `mappings[]`). + * + * mappings..label → the mapping's own `label` + * + * A named import mapping is offered by name in the console's import wizard + * (the saved-mapping selector and the hints that name the chosen mapping), + * so its label is end-user copy. Overlaid by `translateMapping` + * (`i18n-resolver.ts`) on every served `mapping` document + * (`GET /meta/mapping`, the list the wizard reads). The face stops at the + * one string a mapping authors for a reader: its `fieldMapping` entries are + * column names and field names, and the target fields' labels translate + * under `objects..fields`. + */ + mappings: z.record(z.string(), strictObject({ + surface: 'this import mapping translation', + history: TRANSLATION_HISTORY, + aliases: { name: 'label', title: 'label' }, + guidance: { + description: 'an import mapping declares no `description` — only its `label` is shown to a reader, so `label` is the one key to translate', + fieldMapping: 'a mapping\'s `fieldMapping` holds column and field names, not copy — translate a target field\'s label under `objects..fields..label`', + }, + }, { + label: z.string().optional().describe("Translated import mapping label — overlays the mapping's own `label`"), + })).optional().describe('Import-mapping translations keyed by mapping name'), + /** * Translations for **metadata-type configuration forms** — the forms * used by admins to author objects, fields, agents, flows, etc. in the @@ -2582,10 +2609,10 @@ const platformSettingsShape = () => ({ * One locale of a PER-APP translation bundle — `stack.translations`, and * everything {@link defineTranslationBundle} builds. * - * Sixteen groups: every group the platform bundle declares EXCEPT `settings`, + * Seventeen groups: every group the platform bundle declares EXCEPT `settings`, * which is platform-only and is refused here by name with * {@link PER_APP_SETTINGS_PLATFORM_ONLY} as the remedy. See - * {@link PlatformTranslationDataSchema} for the seventeen-group face and for why + * {@link PlatformTranslationDataSchema} for the eighteen-group face and for why * the two are separate namespaces. */ export const TranslationDataSchema = lazySchema(() => strictObject({ @@ -2596,7 +2623,7 @@ export const TranslationDataSchema = lazySchema(() => strictObject({ // `settings`, and an alias prescribing a key the shape rejects is a // suggestion the author cannot take (the `alias-integrity` audit judges // exactly that). Both spellings are answered by `guidance` above instead. - aliases: { object: 'objects', fields: 'objects', app: 'apps', page: 'pages', dashboard: 'dashboards', dataset: 'datasets', report: 'reports', picklist: 'picklists', flow: 'flows', hook: 'hooks', position: 'positions', permission: 'permissions', permissionSets: 'permissions', book: 'books', message: 'messages', strings: 'messages', labels: 'messages', actions: 'globalActions' }, + aliases: { object: 'objects', fields: 'objects', app: 'apps', page: 'pages', dashboard: 'dashboards', dataset: 'datasets', report: 'reports', picklist: 'picklists', flow: 'flows', hook: 'hooks', position: 'positions', permission: 'permissions', permissionSets: 'permissions', book: 'books', mapping: 'mappings', message: 'messages', strings: 'messages', labels: 'messages', actions: 'globalActions' }, // `locale` lives on the ITEM, not on a bundle entry (the bundle keys ARE the // locales). Naming it keeps the suggestion useful for an author who moved a // `translation` item into a bundle and left the field behind. @@ -2606,7 +2633,7 @@ export const TranslationDataSchema = lazySchema(() => strictObject({ export type TranslationData = z.input; /** - * One locale of a PLATFORM translation bundle — the seventeen groups, `settings` + * One locale of a PLATFORM translation bundle — the eighteen groups, `settings` * included. * * The platform's own bundles are code, not authored metadata @@ -2641,7 +2668,7 @@ export const PlatformTranslationDataSchema = lazySchema(() => strictObject({ surface: 'this locale of the platform translation bundle', history: TRANSLATION_HISTORY, guidance: TRANSLATION_KEY_GUIDANCE, - aliases: { object: 'objects', fields: 'objects', app: 'apps', page: 'pages', dashboard: 'dashboards', dataset: 'datasets', report: 'reports', picklist: 'picklists', flow: 'flows', hook: 'hooks', position: 'positions', permission: 'permissions', permissionSets: 'permissions', book: 'books', setting: 'settings', message: 'messages', strings: 'messages', labels: 'messages', actions: 'globalActions' }, + aliases: { object: 'objects', fields: 'objects', app: 'apps', page: 'pages', dashboard: 'dashboards', dataset: 'datasets', report: 'reports', picklist: 'picklists', flow: 'flows', hook: 'hooks', position: 'positions', permission: 'permissions', permissionSets: 'permissions', book: 'books', mapping: 'mappings', setting: 'settings', message: 'messages', strings: 'messages', labels: 'messages', actions: 'globalActions' }, extraKeys: ['locale'], }, { ...appTranslationDataShape(), @@ -2850,7 +2877,7 @@ export type TranslationConfig = z.input; * to whoever — or whatever — authored it. * * `settings` is NOT on this door (#19620, ruling batch #210 item 2 letter B): - * the item takes the PER-APP face, the same sixteen groups as + * the item takes the PER-APP face, the same seventeen groups as * {@link TranslationDataSchema}, and refuses `settings` (and the singular * `setting`) by name with {@link ITEM_SETTINGS_PLATFORM_ONLY} as the remedy. * The file door and the item door are two authoring surfaces for one app @@ -2889,7 +2916,7 @@ export const TranslationItemSchema = lazySchema(() => strictObject({ // this door no longer declares `settings`, and an alias prescribing a key // the shape rejects is a suggestion the author cannot take. Both spellings // are answered by `guidance` above instead. - aliases: { object: 'objects', app: 'apps', page: 'pages', dataset: 'datasets', report: 'reports', picklist: 'picklists', flow: 'flows', hook: 'hooks', position: 'positions', permission: 'permissions', permissionSets: 'permissions', book: 'books', message: 'messages', strings: 'messages', labels: 'messages', actions: 'globalActions', lang: 'locale', language: 'locale' }, + aliases: { object: 'objects', app: 'apps', page: 'pages', dataset: 'datasets', report: 'reports', picklist: 'picklists', flow: 'flows', hook: 'hooks', position: 'positions', permission: 'permissions', permissionSets: 'permissions', book: 'books', mapping: 'mappings', message: 'messages', strings: 'messages', labels: 'messages', actions: 'globalActions', lang: 'locale', language: 'locale' }, }, { ...appTranslationDataShape(), locale: LocaleSchema.describe('BCP-47 locale this item translates (e.g. "zh-CN")'), diff --git a/scripts/fixtures/i18n-walk-parity/every-group.stack.json b/scripts/fixtures/i18n-walk-parity/every-group.stack.json index 5d42786413e..6036bfeaefb 100644 --- a/scripts/fixtures/i18n-walk-parity/every-group.stack.json +++ b/scripts/fixtures/i18n-walk-parity/every-group.stack.json @@ -195,5 +195,13 @@ "description": "How parity is measured", "groups": [{ "key": "basics", "label": "Basics", "include": "parity_*" }] } + ], + "mappings": [ + { + "name": "parity_feed", + "label": "Parity Feed", + "targetObject": "parity_object", + "fieldMapping": [{ "source": "Status", "target": "status" }] + } ] } diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/TranslationPreview.categories-11765.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/TranslationPreview.categories-11765.test.tsx index 55c37c066bb..b58983a49ce 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/TranslationPreview.categories-11765.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/TranslationPreview.categories-11765.test.tsx @@ -27,6 +27,12 @@ import * as React from 'react'; import { describe, it, expect, afterEach } from 'vitest'; import { render, cleanup, screen } from '@testing-library/react'; import { TranslationDataSchema } from '@objectstack/spec/system'; +// `validateMetadataDraft` reaches dynamic `@objectstack/formula`, `@objectstack/lint` +// and `@object-ui/core` imports; their first load is paid here, at collection, +// never inside a case's clock (`check:test-source-alias`). +import '@objectstack/formula'; +import '@objectstack/lint'; +import '@object-ui/core'; import { validateMetadataDraft } from '../clientValidation'; import { t, tFormat } from '../i18n'; @@ -79,6 +85,7 @@ const ONE_ENTRY: Record; key: string; ro key: 'crm_manual', row: () => keys(2), }, + mappings: { data: { lead_feed: { label: 'Import des pistes' } }, key: 'lead_feed', row: () => keys(1) }, metadataForms: { data: { object: { label: 'Objet' } }, key: 'object', row: () => keys(1) }, // `settingsCommon` is one strict object, not a record of author-named nodes: // its members (`sourceLabels`) are what the card counts and samples. diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/TranslationPreview.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/TranslationPreview.tsx index 350d5c14639..245c95e8824 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/TranslationPreview.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/TranslationPreview.tsx @@ -36,6 +36,7 @@ import { BookOpen, ClipboardList, Database, + FileInput, FileText, Gauge, Globe2, @@ -104,6 +105,7 @@ const CATEGORY_DEFS = { positions: { label: 'engine.translationPreview.category.positions', icon: Users, flat: false }, permissions: { label: 'engine.translationPreview.category.permissions', icon: ShieldCheck, flat: false }, books: { label: 'engine.translationPreview.category.books', icon: BookOpen, flat: false }, + mappings: { label: 'engine.translationPreview.category.mappings', icon: FileInput, flat: false }, metadataForms: { label: 'engine.translationPreview.category.metadataForms', icon: FileText, flat: false }, settingsCommon: { label: 'engine.translationPreview.category.settingsCommon', icon: Settings2, flat: false }, } satisfies Record>; diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/adminPreviews.i18n-10862-s2.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/adminPreviews.i18n-10862-s2.test.tsx index e8fa877042e..c25c2387c93 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/adminPreviews.i18n-10862-s2.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/adminPreviews.i18n-10862-s2.test.tsx @@ -474,6 +474,7 @@ describe('TranslationPreview reads the designer locale (objectui#10862)', () => { key: 'engine.translationPreview.category.positions' }, { key: 'engine.translationPreview.category.permissions' }, { key: 'engine.translationPreview.category.books' }, + { key: 'engine.translationPreview.category.mappings' }, { key: 'engine.translationPreview.category.metadataForms' }, { key: 'engine.translationPreview.category.settingsCommon' }, { key: 'engine.translationPreview.categoryEmpty' }, @@ -481,7 +482,7 @@ describe('TranslationPreview reads the designer locale (objectui#10862)', () => { key: 'engine.translationPreview.keyCountOne', vars: { count: 1 } }, ]); // The bundle's own locale is author data, not the designer's language. - expectAsWritten(['French', 'fr-FR', 'account', '"Un"', '2/16 (13%)']); + expectAsWritten(['French', 'fr-FR', 'account', '"Un"', '2/17 (12%)']); }); } }); diff --git a/ui/packages/app-shell/src/views/studio-design/translationTable.test.ts b/ui/packages/app-shell/src/views/studio-design/translationTable.test.ts index cdf5ae40c0a..bb6ea74ac5c 100644 --- a/ui/packages/app-shell/src/views/studio-design/translationTable.test.ts +++ b/ui/packages/app-shell/src/views/studio-design/translationTable.test.ts @@ -200,8 +200,8 @@ describe('readDeclaredStack', () => { expect((stack.views as Doc[])[0]).toMatchObject({ name: 'all_open', object: 'repair_ticket' }); // The owner the platform injects points at the user object, which is walked too. expect(objects.map((o) => o.name).at(-1)).toBe('sys_user'); - // 14 list reads, 11 item reads, 1 platform object. - expect(requests).toBe(14 + 11 + 1); + // 15 list reads, 11 item reads, 1 platform object. + expect(requests).toBe(15 + 11 + 1); expect(fake.calls).toHaveLength(requests); expect(fake.calls).toContain('layered object sys_user '); expect(fake.peak()).toBeLessThanOrEqual(DECLARED_STACK_READ_CONCURRENCY); diff --git a/ui/packages/app-shell/src/views/studio-design/translationTable.ts b/ui/packages/app-shell/src/views/studio-design/translationTable.ts index 622ec4018fc..e2073f2fd7c 100644 --- a/ui/packages/app-shell/src/views/studio-design/translationTable.ts +++ b/ui/packages/app-shell/src/views/studio-design/translationTable.ts @@ -56,6 +56,7 @@ export const WALKED_TYPE_STACK_KEYS = { position: 'positions', permission: 'permissions', book: 'books', + mapping: 'mappings', } as const; export type WalkedType = keyof typeof WALKED_TYPE_STACK_KEYS; diff --git a/ui/packages/i18n/src/namespaces/studio/en.ts b/ui/packages/i18n/src/namespaces/studio/en.ts index 2d6c14c846f..3145aee6313 100644 --- a/ui/packages/i18n/src/namespaces/studio/en.ts +++ b/ui/packages/i18n/src/namespaces/studio/en.ts @@ -4625,6 +4625,7 @@ const STUDIO_EN: Record = { 'engine.translationPreview.category.positions': 'Positions', 'engine.translationPreview.category.permissions': 'Permission Sets', 'engine.translationPreview.category.books': 'Doc Books', + 'engine.translationPreview.category.mappings': 'Import Mappings', 'engine.translationPreview.category.metadataForms': 'Metadata Forms', 'engine.translationPreview.category.settingsCommon': 'Settings UI', 'engine.translationPreview.coverage': 'Category coverage:', diff --git a/ui/packages/i18n/src/namespaces/studio/zh.ts b/ui/packages/i18n/src/namespaces/studio/zh.ts index 3e6a08b8de8..ea2fbc4421c 100644 --- a/ui/packages/i18n/src/namespaces/studio/zh.ts +++ b/ui/packages/i18n/src/namespaces/studio/zh.ts @@ -4158,6 +4158,7 @@ const STUDIO_ZH: Record = { 'engine.translationPreview.category.positions': '岗位', 'engine.translationPreview.category.permissions': '权限集', 'engine.translationPreview.category.books': '文档书', + 'engine.translationPreview.category.mappings': '导入映射', 'engine.translationPreview.category.metadataForms': '元数据表单', 'engine.translationPreview.category.settingsCommon': '设置界面', 'engine.translationPreview.coverage': '分类覆盖率:', diff --git a/ui/packages/i18n/src/utils/spec-translations.ts b/ui/packages/i18n/src/utils/spec-translations.ts index 51f02c8e43d..623bc5c5ffd 100644 --- a/ui/packages/i18n/src/utils/spec-translations.ts +++ b/ui/packages/i18n/src/utils/spec-translations.ts @@ -115,6 +115,9 @@ const SPEC_TRANSLATION_GROUPS = [ // objectstack #26690 serves `books` (a doc book's title, description and // section titles are translatable), copied through onto `app` the same way. 'books', + // objectstack #34939 serves `mappings` (a named import mapping's label, the + // name the import wizard offers it by), copied through onto `app` the same way. + 'mappings', ] as const; function isPlainObject(value: unknown): value is Record {