From 06b0d43d1b1fdfc032195c05d6533006d856de4b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 02:59:12 +0000 Subject: [PATCH 1/5] feat(i18n): approval step label and notification object label read as the metadata translators serve them Claude-Session: https://claude.ai/code/session_01ADHkmQNmyLgnBbCoc2iFjL Co-authored-by: Claude --- .../src/approval-notification-text.ts | 40 ++-- .../src/reader-locale-labels.ts | 31 +-- .../services/service-messaging/src/index.ts | 1 + .../src/notification-text.ts | 203 +++++++++++++++++- .../spec/src/system/i18n-resolver.test.ts | 63 ++++++ packages/spec/src/system/i18n-resolver.ts | 44 ++++ 6 files changed, 349 insertions(+), 33 deletions(-) diff --git a/packages/plugins/plugin-approvals/src/approval-notification-text.ts b/packages/plugins/plugin-approvals/src/approval-notification-text.ts index bcd99e66ccf..ebcb370aa6b 100644 --- a/packages/plugins/plugin-approvals/src/approval-notification-text.ts +++ b/packages/plugins/plugin-approvals/src/approval-notification-text.ts @@ -31,17 +31,33 @@ * the one recipient the text is built for may read it, else the record id * (`ApprovalService.notify` resolves it per recipient); the #23556 / #23594 * ruling B form, label and id for every reader, stands only on the - * reader-less action-link pages. The label rides as a keyed param — `objects..label`, the key the reader-language - * labels (`reader-locale-labels.ts`) and objectql's refusals name an object - * by — so a recipient whose language pack holds it reads it in their language; - * the schema label (the API name when there is none) stands otherwise. + * reader-less action-link pages. [#35384] The label rides as the messaging + * service's typed object-label param, `{ objectLabel: , fallback }`, + * which it resolves per recipient as `GET /meta/object/:name` serves the + * object (`translateObject` with the metadata route's resolve options and the + * packaged base), the way the reader-language labels (`reader-locale-labels.ts`) + * name an object; so a recipient in the deployment's `sourceLocale` reads the + * authored label, a renamed packaged object its rename, and the schema label + * (the API name when there is none) stands when nothing resolves. */ -import { objectLabelKey } from '@objectstack/spec/system'; import { enMessages, type ApprovalMessageId } from './translations/messages.js'; -/** One `{{hole}}` value: the text itself, or a catalog key with the text it falls back to. */ -export type ApprovalTextParam = string | { readonly key: string; readonly fallback: string }; +/** + * One `{{hole}}` value: the text itself, a catalog key with the text it falls + * back to, or [#35384] an object's label by the object's name with the text it + * falls back to (the messaging service's `NotificationObjectLabelParam`). + */ +export type ApprovalTextParam = + | string + | { readonly key: string; readonly fallback: string } + | ApprovalObjectLabelParam; + +/** [#35384] The structural mirror of the messaging service's `NotificationObjectLabelParam`. */ +export interface ApprovalObjectLabelParam { + readonly objectLabel: string; + readonly fallback: string; +} /** * The keyed half — the structural mirror of the messaging service's @@ -68,7 +84,7 @@ export interface ApprovalNotificationText { * not an interface, so it spreads into a sentence's params as it stands. */ export type ApprovalSubjectParams = { - readonly object: { readonly key: string; readonly fallback: string }; + readonly object: ApprovalObjectLabelParam; readonly record: string; }; @@ -78,9 +94,9 @@ export function approvalMessageKey(id: ApprovalMessageId): string { } /** - * The record of `objectName` a notification names: the object's label — keyed - * by `objects..label`, falling back to `objectLabel` (the schema - * label), else the API name — and `record`, the name its recipient reads for + * The record of `objectName` a notification names: the object's label — the + * typed object-label param naming `objectName`, falling back to `objectLabel` + * (the schema label), else the API name — and `record`, the name its recipient reads for * it (its title as they may read it, else its id). */ export function subjectParams( @@ -89,7 +105,7 @@ export function subjectParams( record: string, ): ApprovalSubjectParams { return { - object: { key: objectLabelKey(objectName), fallback: objectLabel ?? objectName }, + object: { objectLabel: objectName, fallback: objectLabel ?? objectName }, record, }; } diff --git a/packages/plugins/plugin-approvals/src/reader-locale-labels.ts b/packages/plugins/plugin-approvals/src/reader-locale-labels.ts index fce0e400d76..a37abb958b3 100644 --- a/packages/plugins/plugin-approvals/src/reader-locale-labels.ts +++ b/packages/plugins/plugin-approvals/src/reader-locale-labels.ts @@ -29,8 +29,8 @@ * - the text is `II18nService.t(key, locale)`; a miss is the key echoed back, * and then the authored text stands. * - * [#35384] Except a METADATA label: the object's, the flow's and the - * position's. Each is resolved by the spec translator of its type + * [#35384] Except a METADATA label: the object's, the flow's, the approval + * step's and the position's. Each is resolved by the spec translator of its type * (`@objectstack/spec/system`) over every locale the service holds, with the * metadata route's `ResolveOptions` ({@link metaLabelTranslation}: the * reader's locale, the DECLARED fallback chain, and the authored language, @@ -44,13 +44,14 @@ * - the flow's by `translateFlow`, the translator the flow runner names a * flow by. `/meta` serves a flow document untranslated (`translateFlow` is * deliberately not in `translateMetadataDocument`'s table), so this is the - * spec's one reading of `flows..label`. + * spec's one reading of `flows..label`; + * - the approval step's by `resolveFlowApprovalStepLabel`, the spec's one + * reading of `flows..approvals..label`, over the flow's name + * and the node's id the stored row carries (no flow document is read). * * So a reader in a deployment's declared `sourceLocale` reads these labels as * authored, never the `defaultLocale` row `t()` falls back to. `t()` carries - * the catalog sentences, and still the approval STEP's label: no spec - * translator reads `flows..approvals..label` yet, and a second - * walk of the locale chain here would be a second resolver. + * the catalog sentences only. * * objectql names a refused write's object this way (`objectDisplayLabel`, * through `objectLabelKey`), the REST door names a NOT NULL field this way @@ -70,9 +71,10 @@ * own `label` (`translation.zod.ts`, `positions`), which `translatePosition` * overlays on every served `position` document. * - * [#35384] Only the step's key is asked of `t()`. The flow and position keys - * are still spelled here, for the contract pin and for the readers that name - * them; `translateFlow` and `translatePosition` read the same addresses. + * [#35384] No key is asked of `t()`. The flow, step and position keys are + * still spelled here, for the contract pin and for the readers that name + * them; `translateFlow`, `resolveFlowApprovalStepLabel` and + * `translatePosition` read the same addresses. * * `` is the request's `process_name` without its `flow:` prefix, the * `Flow.name` the engine hands the node (`$flowName`), and `` is its @@ -100,6 +102,7 @@ import type { II18nService } from '@objectstack/spec/contracts'; import { resolveBundleLocale, + resolveFlowApprovalStepLabel, translateFlow, translateObject, translatePosition, @@ -338,8 +341,6 @@ export function readerLabelsFor( seen.set(key, value); return value; }; - const picked = new Map(); - const pick = (key: string): string | undefined => memo(picked, key, () => render(key)); // [#35384] Built on the first metadata label this read asks, once. let translation: { value: MetaLabelTranslation | undefined } | undefined; /** One metadata label through its spec translator; `undefined` on any miss or throw. */ @@ -359,6 +360,12 @@ export function readerLabelsFor( const doc: FlowLike = { name: flowName }; return translateFlow(doc, bundle, options).label; })); + // [#35384] The step's label, as the spec reads `flows..approvals..label`; + // no literal, so a miss picks nothing and the stored snapshot stands. + const stepLabels = new Map(); + const stepLabel = (flowName: string, nodeId: string): string | undefined => + memo(stepLabels, approvalStepLabelKey(flowName, nodeId), () => + translated(({ bundle, options }) => resolveFlowApprovalStepLabel(bundle, flowName, nodeId, undefined, options))); const positionLabels = new Map(); const positionLabel = (positionName: string): string | undefined => memo(positionLabels, positionName, () => @@ -377,7 +384,7 @@ export function readerLabelsFor( })); return { flowLabel, - stepLabel: (flowName, nodeId) => pick(approvalStepLabelKey(flowName, nodeId)), + stepLabel, objectLabel, positionLabel, sentence: (key, params) => render(key, params), diff --git a/packages/services/service-messaging/src/index.ts b/packages/services/service-messaging/src/index.ts index d9c58985719..337985dd667 100644 --- a/packages/services/service-messaging/src/index.ts +++ b/packages/services/service-messaging/src/index.ts @@ -114,6 +114,7 @@ export { export type { NotificationTextKeys, NotificationTextParam, + NotificationObjectLabelParam, NotificationTextI18n, NotificationTextItem, NotificationTextRendererOptions, diff --git a/packages/services/service-messaging/src/notification-text.ts b/packages/services/service-messaging/src/notification-text.ts index aad90b9804c..bca50ef6a99 100644 --- a/packages/services/service-messaging/src/notification-text.ts +++ b/packages/services/service-messaging/src/notification-text.ts @@ -26,7 +26,20 @@ * ⛔ There is no second catalog here. * - `params` fills the entries' `{{name}}` holes. A value is used as given, * or, spelled `{ key, fallback }`, is itself the recipient-language text of - * `key` (an object's label, `objects..label`), else `fallback`. + * the catalog entry `key`, else `fallback`; or, spelled + * `{ objectLabel, fallback }`, is the label of the object named + * `objectLabel` in the recipient's language, else `fallback`. + * - [#35384] An object's label is METADATA, not a catalog sentence, so the + * `{ objectLabel }` param is resolved as `GET /meta/object/:name` serves it: + * by `translateObject` (`@objectstack/spec/system`) over the object's + * served definition and its packaged base, with the metadata route's + * `ResolveOptions` (the recipient's negotiated locale, the DECLARED + * fallback chain, and the authored language — the declared `sourceLocale` + * else `defaultLocale`). So a recipient in a deployment's `sourceLocale` + * reads the authored label, never the `defaultLocale` row `t()` falls back + * to, and a renamed packaged object reads its rename. A `{ key }` param + * still resolves through `t()`: rows stored before the typed param existed + * render exactly as they did. * - The literal `payload.title` / `payload.body` stay the text delivered * whenever a key cannot be rendered: no `i18n` service, a key with no entry * in the recipient's locale or in the catalog's own fallback locale, a @@ -61,17 +74,41 @@ */ import type { IDataEngine } from '@objectstack/spec/contracts'; -import { resolveBundleLocale } from '@objectstack/spec/system'; +import { + resolveBundleLocale, + translateObject, + type ObjectLike, + type ResolveOptions, + type TranslationBundle, +} from '@objectstack/spec/system'; import { RECIPIENT_LOCALE_FIELD, USER_OBJECT, resolveRecipientLocale } from './recipient-locale.js'; import { FAN_OUT_SYSTEM_CONTEXT } from './fan-out-system-context.js'; import { DEFAULT_LOCALE } from './template-renderer.js'; /** - * One `{{name}}` value of {@link NotificationTextKeys.params}: the text itself, - * or a catalog key rendered in the recipient's language with `fallback` as the - * text when the key has no entry. + * One `{{name}}` value of {@link NotificationTextKeys.params}: the text itself; + * a catalog key rendered in the recipient's language with `fallback` as the + * text when the key has no entry; or [#35384] an object's label, by the + * object's name, resolved as the metadata route serves it with `fallback` as + * the text when nothing resolves ({@link NotificationObjectLabelParam}). */ -export type NotificationTextParam = string | { readonly key: string; readonly fallback: string }; +export type NotificationTextParam = + | string + | { readonly key: string; readonly fallback: string } + | NotificationObjectLabelParam; + +/** + * [#35384] A `{{name}}` value that is the label of the object `objectLabel` + * names (its API name, `crm_deal`), in the recipient's language, as + * `GET /meta/object/:name` serves it: `translateObject` over the object's + * served definition and packaged base, with the metadata route's resolve + * options. `fallback` is the text when nothing resolves (no `i18n` service + * that can hand its translations over, no data engine that knows the object). + */ +export interface NotificationObjectLabelParam { + readonly objectLabel: string; + readonly fallback: string; +} /** * A notification's text as catalog keys (`EmitInput.keyedText`). At least one @@ -92,10 +129,19 @@ export interface RenderedNotificationText { readonly body: string; } -/** The slice of `II18nService` the render asks: `t()`, and `getLocales()` to negotiate when offered. */ +/** + * The slice of `II18nService` the render asks: `t()`, `getLocales()` to + * negotiate when offered, and [#35384] the members an object label is resolved + * by, as the metadata route reads them: `getTranslations()` per locale, and the + * declared `getFallbackLocale()` / `getSourceLocale()` / `getDefaultLocale()`. + */ export interface NotificationTextI18n { t(key: string, locale: string, params?: Record): string; getLocales?(): string[]; + getTranslations?(locale: string): Record; + getFallbackLocale?(): string | undefined; + getSourceLocale?(): string | undefined; + getDefaultLocale?(): string; } /** @@ -112,6 +158,14 @@ const PARAM_NAME_SHAPE = /^\w+$/; const TEXT_MEMBERS: ReadonlySet = new Set(['titleKey', 'bodyKey', 'params']); const KEYED_PARAM_MEMBERS: ReadonlySet = new Set(['key', 'fallback']); +const OBJECT_LABEL_PARAM_MEMBERS: ReadonlySet = new Set(['objectLabel', 'fallback']); + +/** + * An object's API name: one segment of {@link CATALOG_KEY_SHAPE}, so every + * object a `{ key: 'objects..label' }` param could name, the typed + * param names too. + */ +const OBJECT_NAME_SHAPE = /^[A-Za-z0-9_-]+$/; function isPlainObject(value: unknown): value is Record { return value !== null && typeof value === 'object' && !Array.isArray(value); @@ -140,7 +194,19 @@ function problemOf(value: unknown): string | undefined { for (const [name, param] of Object.entries(params)) { if (!PARAM_NAME_SHAPE.test(name)) return `.params has a name '${name}' no {{hole}} can spell`; if (typeof param === 'string') continue; - if (!isPlainObject(param)) return `.params.${name} must be a string or { key, fallback }`; + if (!isPlainObject(param)) return `.params.${name} must be a string, { key, fallback } or { objectLabel, fallback }`; + if ('objectLabel' in param) { + for (const member of Object.keys(param)) { + if (!OBJECT_LABEL_PARAM_MEMBERS.has(member)) { + return `.params.${name} has an undeclared member '${member}' (declared: objectLabel, fallback)`; + } + } + if (typeof param.objectLabel !== 'string' || !OBJECT_NAME_SHAPE.test(param.objectLabel)) { + return `.params.${name}.objectLabel must be an object's API name such as 'crm_deal' (got ${JSON.stringify(param.objectLabel)})`; + } + if (typeof param.fallback !== 'string') return `.params.${name}.fallback must be a string`; + continue; + } for (const member of Object.keys(param)) { if (!KEYED_PARAM_MEMBERS.has(member)) return `.params.${name} has an undeclared member '${member}' (declared: key, fallback)`; } @@ -304,8 +370,17 @@ export class NotificationTextRenderer { ): RenderedNotificationText { const locale = negotiatedLocale(i18n, requested ?? DEFAULT_LOCALE); const params: Record = {}; + // [#35384] Built on the first object label this render asks, once. + let translation: { value: MetaLabelTranslation | undefined } | undefined; for (const [name, param] of Object.entries(keys.params ?? {})) { - params[name] = typeof param === 'string' ? param : (lookup(i18n, param.key, locale) ?? param.fallback); + if (typeof param === 'string') { + params[name] = param; + } else if ('objectLabel' in param) { + translation ??= { value: metaLabelTranslation(i18n, locale) }; + params[name] = this.objectLabel(translation.value, param.objectLabel) ?? param.fallback; + } else { + params[name] = lookup(i18n, param.key, locale) ?? param.fallback; + } } const entry = (key: string): string | undefined => announceMisses ? this.entry(i18n, key, locale, params) @@ -316,6 +391,33 @@ export class NotificationTextRenderer { }; } + /** + * [#35384] The label of `objectName` as `GET /meta/object/:name` serves it + * in the options' locale: `translateObject` over the object's served + * definition (`getSchema`, its `label` a code extension's rename included) + * with its packaged base (`registry.getPackagedObjectBase`, ADR-0029 + * D9.2a), the two reads the metadata route's own accessors make, off the + * data engine this renderer already reads recipients from. `undefined` + * when nothing resolves: no translation to resolve with, no engine that + * knows the object, or a throw (a misbehaving service costs the language, + * never the delivery). + */ + private objectLabel(translation: MetaLabelTranslation | undefined, objectName: string): string | undefined { + if (!translation) return undefined; + try { + const data = this.opts.getData() as unknown as ObjectLabelSource | undefined; + const served = labelText(servedObjectDef(data, objectName)?.label); + const doc: ObjectLike = { name: objectName, ...(served !== undefined ? { label: served } : {}) }; + const packagedBase = packagedBaseOf(data, objectName); + return labelText(translateObject(doc, translation.bundle, { + ...translation.options, + ...(packagedBase !== undefined ? { packagedBase } : {}), + }).label); + } catch { + return undefined; + } + } + /** A title/body entry, or `undefined` (said once per key and locale) when the catalog holds none. */ private entry( i18n: NotificationTextI18n, @@ -338,6 +440,89 @@ export class NotificationTextRenderer { } } +/** What an object label is translated with: the bundle and the metadata route's `ResolveOptions`. */ +interface MetaLabelTranslation { + readonly bundle: TranslationBundle | undefined; + readonly options: ResolveOptions; +} + +/** + * [#35384] What the metadata route (`GET /meta/object/:name`) translates an + * object with, for a recipient in `locale`: the bundle, every locale `i18n` + * holds keyed by locale (`translationBundleOf` in rest), and the + * `ResolveOptions` that route builds (`metaTranslateOptions` in rest): the + * locale, the DECLARED fallback chain (`getFallbackLocale()`), and the + * authored language, the declared `sourceLocale` (`getSourceLocale()`) else + * `defaultLocale` (`getDefaultLocale()`). Each getter is feature-detected; a + * service that declares none gets none. The locale is the negotiated one, as + * objectql's refusal labels and the approvals reader hand it. + * + * `undefined` for a service that cannot hand its translations over (no + * `getLocales` / `getTranslations`) or that throws: the param's fallback + * stands. + */ +function metaLabelTranslation(i18n: NotificationTextI18n, locale: string): MetaLabelTranslation | undefined { + if (typeof i18n.getLocales !== 'function' || typeof i18n.getTranslations !== 'function') return undefined; + try { + const bundle: Record = {}; + for (const code of i18n.getLocales()) { + const data = i18n.getTranslations(code); + if (data && typeof data === 'object') bundle[code] = data; + } + const fallback = typeof i18n.getFallbackLocale === 'function' ? i18n.getFallbackLocale() : undefined; + const source = typeof i18n.getSourceLocale === 'function' ? i18n.getSourceLocale() : undefined; + const authored = typeof source === 'string' && source.length > 0 + ? source + : typeof i18n.getDefaultLocale === 'function' ? i18n.getDefaultLocale() : undefined; + const options: ResolveOptions = { + locale, + ...(typeof fallback === 'string' && fallback.length > 0 ? { fallbackChain: [fallback] } : {}), + ...(typeof authored === 'string' && authored.length > 0 ? { defaultLocale: authored } : {}), + }; + return { bundle: Object.keys(bundle).length > 0 ? (bundle as TranslationBundle) : undefined, options }; + } catch { + return undefined; + } +} + +/** + * [#35384] Where an object's label is served from: the data engine's + * `getSchema(name)` (the served definition) and `registry.getPackagedObjectBase(name)` + * (the packaged declaration). Each member is feature-detected. + */ +interface ObjectLabelSource { + getSchema?(objectName: string): unknown; + registry?: unknown; +} + +/** The object's served definition, `undefined` when the source cannot answer. */ +function servedObjectDef(source: ObjectLabelSource | undefined, objectName: string): Record | undefined { + if (!source || typeof source.getSchema !== 'function') return undefined; + try { + const def = source.getSchema(objectName); + return def && typeof def === 'object' ? (def as Record) : undefined; + } catch { + return undefined; + } +} + +/** The object's packaged base, `undefined` when none is known (the translator then answers from the catalog). */ +function packagedBaseOf(source: ObjectLabelSource | undefined, objectName: string): unknown { + const registry = source?.registry as { getPackagedObjectBase?: (name: string) => unknown } | undefined; + if (!registry || typeof registry.getPackagedObjectBase !== 'function') return undefined; + try { + const base = registry.getPackagedObjectBase(objectName); + return base && typeof base === 'object' ? base : undefined; + } catch { + return undefined; + } +} + +/** A non-blank label, or `undefined`. */ +function labelText(value: unknown): string | undefined { + return typeof value === 'string' && value.trim().length > 0 ? value : undefined; +} + /** `t()`'s answer, or `undefined` for a miss (`t()` echoes the key), an empty answer or a throw. */ function lookup( i18n: NotificationTextI18n, diff --git a/packages/spec/src/system/i18n-resolver.test.ts b/packages/spec/src/system/i18n-resolver.test.ts index 858e9ecbcad..36d3fc33119 100644 --- a/packages/spec/src/system/i18n-resolver.test.ts +++ b/packages/spec/src/system/i18n-resolver.test.ts @@ -6845,3 +6845,66 @@ describe('bundle locale keys are the bundle\'s OWN keys — an Object.prototype expect(resolveBundleLocale(bare, 'toString')).toBeUndefined(); }); }); + +// ════════════════════════════════════════════════════════════════════════════ +// #35384 — an approval step's label, `flows..approvals..label` +// ════════════════════════════════════════════════════════════════════════════ + +import { resolveFlowApprovalStepLabel } from './i18n-resolver'; + +describe('resolveFlowApprovalStepLabel — an approval step label from the `flows` bundle group (#35384)', () => { + const bundle: FlowTestBundle = { + en: { flows: { expense_approval: { approvals: { manager_review: { label: 'Manager review (en pack)' } } } } }, + 'zh-CN': { flows: { expense_approval: { approvals: { manager_review: { label: '经理审批' } } } } }, + }; + + it('resolves flows..approvals..label in the requested locale', () => { + expect(resolveFlowApprovalStepLabel(bundle, 'expense_approval', 'manager_review', 'Manager review', { locale: 'zh-CN' })) + .toBe('经理审批'); + // The BCP-47 ladder the rest of the surface uses: a bare `zh` reaches the zh-CN pack. + expect(resolveFlowApprovalStepLabel(bundle, 'expense_approval', 'manager_review', undefined, { locale: 'zh' })) + .toBe('经理审批'); + }); + + it('walks the DECLARED fallback chain for a non-authored locale, and nothing undeclared', () => { + expect(resolveFlowApprovalStepLabel(bundle, 'expense_approval', 'manager_review', 'Manager review', { + locale: 'ja-JP', fallbackChain: ['zh-CN'], defaultLocale: 'en', + })).toBe('经理审批'); + expect(resolveFlowApprovalStepLabel(bundle, 'expense_approval', 'manager_review', 'Manager review', { locale: 'ja-JP' })) + .toBe('Manager review'); + }); + + it('an authored-locale reader (sourceLocale en, defaultLocale zh-CN) never reaches the zh-CN row', () => { + const authoredOnly: FlowTestBundle = { + 'zh-CN': { flows: { expense_approval: { approvals: { manager_review: { label: '经理审批' } } } } }, + }; + // The serving layer hands `defaultLocale` the declared sourceLocale (en), + // and the declared fallback chain (zh-CN, the defaultLocale collapse). + const opts = { locale: 'en', fallbackChain: ['zh-CN'], defaultLocale: 'en' }; + expect(resolveFlowApprovalStepLabel(authoredOnly, 'expense_approval', 'manager_review', 'Manager review', opts)) + .toBe('Manager review'); + expect(resolveFlowApprovalStepLabel(authoredOnly, 'expense_approval', 'manager_review', undefined, opts)) + .toBeUndefined(); + // A shipped bundle entry for the authored locale still wins. + expect(resolveFlowApprovalStepLabel(bundle, 'expense_approval', 'manager_review', 'Manager review', opts)) + .toBe('Manager review (en pack)'); + }); + + it('falls back to the literal, then undefined: no bundle, an empty bundle, an unknown flow or node', () => { + expect(resolveFlowApprovalStepLabel(undefined, 'expense_approval', 'manager_review', 'Manager review', { locale: 'zh-CN' })) + .toBe('Manager review'); + expect(resolveFlowApprovalStepLabel({}, 'expense_approval', 'manager_review', undefined, { locale: 'zh-CN' })) + .toBeUndefined(); + expect(resolveFlowApprovalStepLabel(bundle, 'other_flow', 'manager_review', 'Step', { locale: 'zh-CN' })) + .toBe('Step'); + expect(resolveFlowApprovalStepLabel(bundle, 'expense_approval', 'director_review', undefined, { locale: 'zh-CN' })) + .toBeUndefined(); + expect(resolveFlowApprovalStepLabel(bundle, 'expense_approval', '', 'Step', { locale: 'zh-CN' })) + .toBe('Step'); + }); + + it('reads own node ids only, never a prototype member', () => { + expect(resolveFlowApprovalStepLabel(bundle, 'expense_approval', 'toString', undefined, { locale: 'zh-CN' })) + .toBeUndefined(); + }); +}); diff --git a/packages/spec/src/system/i18n-resolver.ts b/packages/spec/src/system/i18n-resolver.ts index 78cca8dc84b..eba7ced87d6 100644 --- a/packages/spec/src/system/i18n-resolver.ts +++ b/packages/spec/src/system/i18n-resolver.ts @@ -6796,6 +6796,50 @@ export function resolveFlowScreenTitle( return lookupFlowScreenCopy(bundle, flowName, screen.nodeId, opts)?.title ?? literal; } +/** + * [#35384] Resolve an approval step's label against + * `flows..approvals..label` — the `approvals` group's one + * key, which overlays the `approval` node's own `FlowNode.label` (the step + * name an approval request snapshots as `current_step_label`) — falling back + * to `literal`, and to `undefined` when none is given: the same + * bundle-then-literal order {@link resolveFlowScreenTitle} follows, across the + * same locale chain ({@link ResolveOptions}: the requested locale, then the + * DECLARED fallback chain, unless the requested locale is the authored one). + * + * Takes the flow's name and the node's id, not a flow document, because its + * reader holds no document: an approval request row carries the flow's name + * (`process_name` without its `flow:` prefix) and the node's id + * (`current_step`), and a list read must not read a flow per row. A caller + * holding a document passes the node's authored `label` as `literal`. + * + * Every depth: the key is addressed by `FlowNode.id` alone, so an approval + * node inside an ADR-0031 region resolves like a top-level one. + * + * ⛔ Not folded into {@link translateFlow}: that translator leaves every + * node's `label` alone (the Studio canvas draws it), and its document readers + * hand it a name-and-label stub, so a node overlay there would reach no + * reader of this key. + */ +export function resolveFlowApprovalStepLabel( + bundle: TranslationBundle | undefined, + flowName: string, + nodeId: string, + literal?: string, + opts?: ResolveOptions, +): string | undefined { + if (!bundle || !flowName || typeof nodeId !== 'string' || nodeId.length === 0) return literal; + for (const code of localeChain(opts)) { + const entry = pickData(bundle, code)?.flows?.[flowName]?.approvals; + if (!entry || typeof entry !== 'object') continue; + // Own keys only: a node id that reads as `toString` must not resolve to + // the map's prototype member. + if (!Object.prototype.hasOwnProperty.call(entry, nodeId)) continue; + const candidate = (entry as Record)[nodeId]?.label; + if (typeof candidate === 'string' && candidate.length > 0) return candidate; + } + return literal; +} + /** * Apply the active locale to a flow metadata document (#7646's recommendation * B, the resolver half #11287): translates the flow's own `label` against From e727a36483abdd82c3aa3ea9ec3b66a47e64f806 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 03:06:24 +0000 Subject: [PATCH 2/5] test(i18n): pin the approval step label and the notification object label against /meta's reading Claude-Session: https://claude.ai/code/session_01ADHkmQNmyLgnBbCoc2iFjL Co-authored-by: Claude --- ...tep-label-and-notification-object-label.md | 18 ++ ...otification-keyed-text.integration.test.ts | 78 +++++++++ .../src/reader-locale-labels.test.ts | 59 +++++-- ...eyed-notification-text.integration.test.ts | 160 +++++++++++++++++- packages/spec/liveness/translation.json | 4 +- 5 files changed, 299 insertions(+), 20 deletions(-) create mode 100644 .changeset/35384-step-label-and-notification-object-label.md diff --git a/.changeset/35384-step-label-and-notification-object-label.md b/.changeset/35384-step-label-and-notification-object-label.md new file mode 100644 index 00000000000..02afc5c4c6f --- /dev/null +++ b/.changeset/35384-step-label-and-notification-object-label.md @@ -0,0 +1,18 @@ +--- +'@objectstack/spec': patch +'@objectstack/service-messaging': patch +'@objectstack/plugin-approvals': patch +--- + +fix(i18n): an approval step label and an approval notification's object label read as the metadata translators serve them + +Clause-②: yes (widening) +Metadata-protocol: none + +In a deployment whose `i18n.sourceLocale` differs from its `i18n.defaultLocale` (an app authored in English that defaults its users to Chinese), an English reader was shown the Chinese approval step name, and an English approval-notification recipient read the Chinese object name inside an English sentence. Both labels were read through `II18nService.t()`, which falls back to the `defaultLocale` row; `/meta` serves the authored text. Both now resolve the way the metadata route resolves a label: the reader's negotiated locale, the declared fallback chain, and the authored language (the declared `sourceLocale`, else `defaultLocale`). + +- **`@objectstack/spec`** adds `resolveFlowApprovalStepLabel(bundle, flowName, nodeId, literal?, opts?)` (`@objectstack/spec/system`), the one reading of `flows..approvals..label`: the requested locale, then the declared fallback chain (skipped for the authored locale), then `literal`. It takes the flow's name and the node's id, so a reader holding only an approval request row needs no flow document. +- **`@objectstack/service-messaging`** accepts a new `NotificationTextKeys.params` value, `{ objectLabel: '', fallback }` (`NotificationObjectLabelParam`): the label of that object in the recipient's language, resolved as `GET /meta/object/:name` serves it, by `translateObject` over the object's served definition and its packaged base, so a renamed packaged object is named by its rename. It renders the same way on the inline fan-out, the dispatcher (digests included) and the inbox reader. `fallback` is delivered when nothing resolves. The `{ key, fallback }` value is still accepted and still renders through `t()`, so stored deliveries and inbox rows render as before. +- **`@objectstack/plugin-approvals`** names a notification's object with that typed param, and reads the approval step label through `resolveFlowApprovalStepLabel`, so `t()` carries catalog sentences only. + +Upgrade `@objectstack/plugin-approvals` and `@objectstack/service-messaging` together: an older messaging service refuses the typed param at `emit()`. diff --git a/packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts b/packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts index 6d94be6a778..7fe9128d913 100644 --- a/packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts +++ b/packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts @@ -361,3 +361,81 @@ describe('#24978 — end to end: a real messaging service renders each approver\ ]); }); }); + +/** + * [#35384] The object an approval notification names is labelled as + * `GET /meta/object/:name` serves it: the subject param is the messaging + * service's typed object-label param (`{ objectLabel, fallback }`), resolved + * per recipient by `translateObject` with the metadata route's resolve options + * and the object's packaged base, never through `t()`. + * + * The deployment: authored in English (`sourceLocale: 'en'`), defaulting its + * users to Chinese (`defaultLocale` and the declared fallback `zh-CN`), with a + * `zh-CN` pack for the object. `t('objects.crm_deal.label', 'en')` falls to the + * `zh-CN` row, so before this an English approver read `商机` inside an + * English sentence. CONTROL: the Chinese approver still reads `商机`. + */ +describe('[#35384] the object an approval notification names reads as /meta serves it', () => { + /** The en-authored, zh-CN-default deployment's i18n service. */ + const sourceLocaleI18n = () => { + const i18n = i18nWithBundle('zh-CN'); + i18n.setFallbackLocale('zh-CN'); + i18n.setSourceLocale('en'); + // The served adapter's shape (`FileI18nAdapter`): the declared fallback, read back. + return Object.assign(i18n, { getFallbackLocale: () => 'zh-CN' }); + }; + + /** Open one request on a fresh engine; `rename` extends the packaged `Deal` into a new label first. */ + const openOn = async (rename?: string) => { + const engine = await bootEngine([ + { id: 'u_sub', name: 'Sun Submitter', email: 'sun@example.com', locale: 'zh-CN' }, + { id: 'u_zh', name: 'Zhang', email: 'zhang@example.com', locale: 'zh-CN' }, + { id: 'u_en', name: 'Ada', email: 'ada@example.com', locale: 'en' }, + ]); + try { + if (rename) engine.registry.registerObjectExtension({ extend: 'crm_deal', label: rename } as never, 'com.acme.crm.custom'); + const i18n = sourceLocaleI18n(); + const getData = () => engine as any; + const messaging = new MessagingService({ + logger: silent, + getData, + textRenderer: new NotificationTextRenderer({ + getData, getI18n: () => i18n, getDefaultLocale: () => i18n.getDefaultLocale(), logger: silent, + }), + }); + messaging.registerChannel(createInboxChannel({ getData })); + let now = Date.parse('2026-10-01T09:00:00.000Z'); + const svc = approvalService(engine, () => new Date(now += 1000)); + svc.attachMessaging(messaging as any); + await engine.insert('crm_deal', { id: 'D_1', title: 'Big deal', organization_id: ORG }, { context: SYSTEM } as any); + await svc.openNodeRequest({ + object: 'crm_deal', recordId: 'D_1', runId: 'run_1', nodeId: 'review', flowName: FLOW.name, + config: { approvers: [{ type: 'user', value: 'u_zh' }, { type: 'user', value: 'u_en' }], behavior: 'first_response' } as any, + submitterId: 'u_sub', record: { id: 'D_1', title: 'Big deal' }, + }, asUser('u_sub')); + const bodyOf = async (userId: string) => { + const rows = (await engine.find('sys_inbox_message', { where: { user_id: userId }, fields: ['body_md'] }, { context: SYSTEM })) as any[]; + return rows.map((r) => r.body_md); + }; + return { en: await bodyOf('u_en'), zh: await bodyOf('u_zh'), i18n }; + } finally { + try { await engine.destroy(); } catch { /* noop */ } + } + }; + + it("the defect's precondition: t() answers an en reader with the zh-CN row", () => { + expect(sourceLocaleI18n().t('objects.crm_deal.label', 'en')).toBe('商机'); + }); + + it('an en approver reads the authored label; CONTROL: a zh-CN approver reads the zh-CN row', async () => { + const { en, zh } = await openOn(); + expect(en).toEqual(['A decision on Deal Big deal is waiting on you.']); + expect(zh).toEqual(['商机 Big deal 正在等待您的审批决定。']); + }); + + it('a renamed packaged object is named by its rename, in every language, as /meta names it', async () => { + const { en, zh } = await openOn('Opportunity'); + expect(en).toEqual(['A decision on Opportunity Big deal is waiting on you.']); + expect(zh).toEqual(['Opportunity Big deal 正在等待您的审批决定。']); + }); +}); diff --git a/packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts b/packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts index b10441a4405..f9d9a72fdb8 100644 --- a/packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts +++ b/packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts @@ -110,10 +110,12 @@ describe('[#24863] the pick', () => { it('negotiates through `resolveBundleLocale` even for a service that resolves exactly', () => { // A service that answers only the exact tag it holds, as `FileI18nAdapter` does. - // [#35384] Asked of the step's label, the one label still read through `t()`. + // [#35384] Asked of the step's label, now read off the service's translations. + const packs: Record> = { en: {}, 'zh-CN': packOf({ [approvalStepLabelKey('f', 'n')]: '步骤' }) }; const exact: ReaderLabelI18n = { - t: (key, locale) => (locale === 'zh-CN' && key === approvalStepLabelKey('f', 'n') ? '步骤' : key), + t: (key) => key, getLocales: () => ['en', 'zh-CN'], + getTranslations: (locale) => packs[locale] ?? {}, }; expect(readerLabelsFor(exact, 'zh')!.stepLabel('f', 'n')).toBe('步骤'); }); @@ -144,13 +146,19 @@ describe('[#24863] the pick', () => { expect(readerLabelsFor(undefined, 'zh-CN')).toBeUndefined(); }); - it('asks the service once per key per read', () => { + it('asks the service once per read, and never through t()', () => { const asked: string[] = []; - const counting: ReaderLabelI18n = { t: (key) => { asked.push(key); return key; } }; + let reads = 0; + const counting: ReaderLabelI18n = { + t: (key) => { asked.push(key); return key; }, + getLocales: () => ['zh-CN'], + getTranslations: () => { reads += 1; return packOf(ZH); }, + }; const labels = readerLabelsFor(counting, 'zh-CN')!; - labels.stepLabel('f', 'n'); - labels.stepLabel('f', 'n'); - expect(asked).toEqual([approvalStepLabelKey('f', 'n')]); + expect(labels.stepLabel('account_approval', 'manager_review')).toBe('经理审核'); + labels.stepLabel('account_approval', 'manager_review'); + expect(reads).toBe(1); + expect(asked).toEqual([]); }); }); @@ -285,11 +293,13 @@ describe('[#35384] the object label in the declared sourceLocale reads as author }); /** - * [#35384] The flow's and the position's labels are metadata too, so they are - * resolved by the spec translators of their types — `translateFlow` (the - * flow runner's reading of `flows..label`; `/meta` serves a flow - * document untranslated) and `translatePosition` (what `GET /meta/position` - * serves) — with `/meta`'s `ResolveOptions`, and never through `t()`. + * [#35384] The flow's, the approval step's and the position's labels are + * metadata too, so they are resolved by the spec readers of their keys — + * `translateFlow` (the flow runner's reading of `flows..label`; `/meta` + * serves a flow document untranslated), `resolveFlowApprovalStepLabel` (the + * one reading of `flows..approvals..label`) and + * `translatePosition` (what `GET /meta/position` serves) — with `/meta`'s + * `ResolveOptions`, and never through `t()`. * * The scenario: an app authored in English (`sourceLocale: 'en'`) that * defaults its users to Chinese (`defaultLocale: 'zh-CN'`, declared fallback @@ -301,7 +311,7 @@ describe('[#35384] the object label in the declared sourceLocale reads as author * read by an `en` reader, and with no `sourceLocale` declared an `en` reader * walks the declared fallback to the `zh-CN` rows. */ -describe('[#35384] the flow and position labels in the declared sourceLocale read as authored', () => { +describe('[#35384] the flow, approval step and position labels in the declared sourceLocale read as authored', () => { const EN = { [flowLabelKey('other_flow')]: 'Other flow' }; const declared = (sourceLocale: string | undefined, en: Record = EN) => { const i18n = i18nWith({ 'zh-CN': ZH, en }); @@ -320,6 +330,7 @@ describe('[#35384] the flow and position labels in the declared sourceLocale rea it('the defect\'s precondition: t() answers an en reader with the zh-CN rows', () => { const i18n = declared('en'); expect(i18n.t(flowLabelKey('account_approval'), 'en')).toBe('客户审批'); + expect(i18n.t(approvalStepLabelKey('account_approval', 'manager_review'), 'en')).toBe('经理审核'); expect(i18n.t(positionLabelKey('crm_sales_manager'), 'en')).toBe('销售经理'); }); @@ -328,27 +339,36 @@ describe('[#35384] the flow and position labels in the declared sourceLocale rea }); for (const locale of ['en', 'en-US']) { - it(`an ${locale} reader picks no defaultLocale row: the flow and position labels stand as authored`, () => { + it(`an ${locale} reader picks no defaultLocale row: the flow, step and position labels stand as authored`, () => { const labels = readerLabelsFor(declared('en'), locale)!; expect(labels.flowLabel('account_approval')).toBeUndefined(); + expect(labels.stepLabel('account_approval', 'manager_review')).toBeUndefined(); expect(labels.positionLabel('crm_sales_manager')).toBeUndefined(); const row = served(); localizeRequestLabels(row, labels); expect(row.process_label).toBe('Account Approval'); + expect(row.step_label).toBe('Manager Review'); + expect(row.current_step_label).toBe('Manager Review'); }); } it('CONTROL: a zh-CN reader still reads the zh-CN rows', () => { const labels = readerLabelsFor(declared('en'), 'zh-CN')!; expect(labels.flowLabel('account_approval')).toBe('客户审批'); + expect(labels.stepLabel('account_approval', 'manager_review')).toBe('经理审核'); expect(labels.positionLabel('crm_sales_manager')).toBe('销售经理'); }); it('CONTROL: an en pack entry is what an en and an en-US reader read', () => { - const en = { [flowLabelKey('account_approval')]: 'Account sign-off', [positionLabelKey('crm_sales_manager')]: 'Sales lead' }; + const en = { + [flowLabelKey('account_approval')]: 'Account sign-off', + [approvalStepLabelKey('account_approval', 'manager_review')]: 'Manager sign-off', + [positionLabelKey('crm_sales_manager')]: 'Sales lead', + }; for (const locale of ['en', 'en-US']) { const labels = readerLabelsFor(declared('en', en), locale)!; expect(labels.flowLabel('account_approval')).toBe('Account sign-off'); + expect(labels.stepLabel('account_approval', 'manager_review')).toBe('Manager sign-off'); expect(labels.positionLabel('crm_sales_manager')).toBe('Sales lead'); } }); @@ -356,13 +376,18 @@ describe('[#35384] the flow and position labels in the declared sourceLocale rea it('CONTROL: with no sourceLocale declared, an en reader walks the declared fallback to the zh-CN rows', () => { const labels = readerLabelsFor(declared(undefined), 'en')!; expect(labels.flowLabel('account_approval')).toBe('客户审批'); + expect(labels.stepLabel('account_approval', 'manager_review')).toBe('经理审核'); expect(labels.positionLabel('crm_sales_manager')).toBe('销售经理'); }); - it('reads neither label through t(): a service that cannot hand its translations over picks none', () => { - const tOnly: ReaderLabelI18n = { t: (key) => (key === flowLabelKey('f') ? '流程' : key === positionLabelKey('p') ? '岗位' : key) }; + it('reads no label through t(): a service that cannot hand its translations over picks none', () => { + const tOnly: ReaderLabelI18n = { + t: (key) => (key === flowLabelKey('f') ? '流程' : key === positionLabelKey('p') ? '岗位' + : key === approvalStepLabelKey('f', 'n') ? '步骤' : key), + }; const labels = readerLabelsFor(tOnly, 'zh-CN')!; expect(labels.flowLabel('f')).toBeUndefined(); + expect(labels.stepLabel('f', 'n')).toBeUndefined(); expect(labels.positionLabel('p')).toBeUndefined(); }); diff --git a/packages/services/service-messaging/src/keyed-notification-text.integration.test.ts b/packages/services/service-messaging/src/keyed-notification-text.integration.test.ts index 71408eb7ee1..aa314d29cee 100644 --- a/packages/services/service-messaging/src/keyed-notification-text.integration.test.ts +++ b/packages/services/service-messaging/src/keyed-notification-text.integration.test.ts @@ -51,7 +51,8 @@ import { NotificationTemplateStore } from './template-renderer.js'; import { SqlNotificationOutbox, DELIVERY_OBJECT } from './sql-outbox.js'; import { MemoryNotificationOutbox } from './memory-outbox.js'; import { NotificationDispatcher } from './dispatcher.js'; -import { NotificationTextRenderer } from './notification-text.js'; +import { NotificationTextRenderer, type NotificationTextKeys } from './notification-text.js'; +import { translateMetadataDocument } from '@objectstack/spec/system'; import { DIGEST_HEADING_KEY } from './digest-render.js'; import { MessagingTranslations } from './translations/index.js'; import { enMessages as messagingEnMessages, messagingMessages } from './translations/messages.js'; @@ -722,3 +723,160 @@ describe("#32240 — an inbox row reads in the READER's language", () => { expect(await readAs(ql, 'u_none', 'ja-JP')).toEqual([{ title: LITERAL.title, body_md: LITERAL.body }]); }); }); + +/** + * [#35384] The typed object-label param, `{ objectLabel, fallback }`: an + * object's label is METADATA, so it is resolved as `GET /meta/object/:name` + * serves it — `translateObject` over the object's served definition and its + * packaged base, with the metadata route's resolve options (the recipient's + * negotiated locale, the declared fallback chain, the declared `sourceLocale` + * else `defaultLocale`) — on the inline fan-out, on the durable path and on + * the inbox reader's render. The `{ key, fallback }` param keeps its `t()` + * reading, so a row stored before the typed param existed renders as it did. + * + * The deployment: authored in English (`sourceLocale: 'en'`), defaulting its + * users to Chinese (`defaultLocale` and the declared fallback `zh-CN`), with a + * `zh-CN` pack holding the object's label. `t('objects.crm_deal.label', 'en')` + * falls to the `zh-CN` row. The oracle is `/meta`'s own call, + * `translateMetadataDocument('object', served, bundle, { …options, packagedBase })`. + */ +describe('#35384 — an object label param reads as /meta serves the object', () => { + const DEAL_CATALOG: Record> = { + en: { messages: { dealTitle: 'Approval requested', dealBody: 'Your {{object}} {{record}} awaits approval.' } }, + 'zh-CN': { + messages: { dealTitle: '审批请求', dealBody: '您的{{object}} {{record}} 待审批。' }, + objects: { crm_deal: { label: '商机' } }, + }, + }; + const TYPED: NotificationTextKeys = { + titleKey: 'messages.dealTitle', + bodyKey: 'messages.dealBody', + params: { object: { objectLabel: 'crm_deal', fallback: 'Opportunity' }, record: 'D_1' }, + }; + const LEGACY: NotificationTextKeys = { + ...TYPED, + params: { object: { key: 'objects.crm_deal.label', fallback: 'Opportunity' }, record: 'D_1' }, + }; + const DEAL_LITERAL = { title: 'Approval requested', body: 'Your Opportunity D_1 awaits approval.' }; + const enBody = (label: string) => `Your ${label} D_1 awaits approval.`; + const zhBody = (label: string) => `您的${label} D_1 待审批。`; + + /** The en-authored, zh-CN-default deployment's i18n service, as `AppPlugin` declares it. */ + function sourceLocaleI18n() { + const i18n = createMemoryI18n(); + for (const [locale, data] of Object.entries(DEAL_CATALOG)) i18n.loadTranslations(locale, data); + i18n.setDefaultLocale('zh-CN'); + i18n.setFallbackLocale('zh-CN'); + i18n.setSourceLocale('en'); + // The served adapter's shape (`FileI18nAdapter`): the declared fallback, read back. + return Object.assign(i18n, { getFallbackLocale: (): string | undefined => 'zh-CN' }); + } + + /** A real engine holding `crm_deal` as a package declares it, renamed by a code extension when `rename` is given. */ + async function bootDeal(rename?: string): Promise { + const ql = await boot(); + ql.registry.registerObject( + { name: 'crm_deal', label: 'Opportunity', fields: { name: { type: 'text', label: 'Name' } } } as never, + 'com.acme.crm', undefined, 'own', + ); + if (rename) ql.registry.registerObjectExtension({ extend: 'crm_deal', label: rename } as never, 'com.acme.crm.custom'); + return ql; + } + + /** What `GET /meta/object/crm_deal` serves as the label for a request in `locale`. */ + function metaLabel(ql: ObjectQL, locale: string): unknown { + const i18n = sourceLocaleI18n(); + const bundle = Object.fromEntries(i18n.getLocales().map((code) => [code, i18n.getTranslations(code)])); + return translateMetadataDocument('object', ql.getSchema('crm_deal') as never, bundle as never, { + locale, fallbackChain: ['zh-CN'], defaultLocale: 'en', + packagedBase: ql.registry.getPackagedObjectBase('crm_deal'), + }).label; + } + + const emitDeal = (audience: string[], keyedText: NotificationTextKeys, over: Partial = {}): EmitInput => ({ + topic: 'deal.approval', audience, organizationId: ORG, channels: ['inbox'], + payload: { ...DEAL_LITERAL }, keyedText, ...over, + }); + + it("the defect's precondition: t() answers an en reader with the zh-CN row, and so does the { key } param", async () => { + const ql = await bootDeal(); + const i18n = sourceLocaleI18n(); + expect(i18n.t('objects.crm_deal.label', 'en')).toBe('商机'); + const c = compose(ql, { i18n }); + await c.messaging.emit(emitDeal(['u_en'], LEGACY)); + expect((await inboxOf(ql, 'u_en'))[0]?.body_md).toBe(enBody('商机')); + }); + + it('inline fan-out: an en recipient reads the authored label; CONTROL: a zh-CN recipient reads the zh-CN row', async () => { + const ql = await bootDeal(); + const c = compose(ql, { i18n: sourceLocaleI18n() }); + await c.messaging.emit(emitDeal(['u_en', 'u_zh'], TYPED)); + expect(metaLabel(ql, 'en')).toBe('Opportunity'); + expect(metaLabel(ql, 'zh-CN')).toBe('商机'); + expect(await inboxOf(ql, 'u_en')).toEqual([{ title: 'Approval requested', body_md: enBody('Opportunity') }]); + expect(await inboxOf(ql, 'u_zh')).toEqual([{ title: '审批请求', body_md: zhBody('商机') }]); + }); + + it('durable path (SQL outbox + dispatcher): the same, and the snapshot stores the typed param as emitted', async () => { + const ql = await bootDeal(); + const c = compose(ql, { i18n: sourceLocaleI18n(), outbox: 'sql' }); + expect((await c.messaging.emit(emitDeal(['u_en', 'u_zh'], TYPED))).enqueued).toBe(2); + const [row] = (await ql.find(DELIVERY_OBJECT, { fields: ['payload'] }, SYSTEM)) as any[]; + const payload = typeof row.payload === 'string' ? JSON.parse(row.payload) : row.payload; + expect(payload.keyedText).toEqual(TYPED); + await c.dispatcher!.tick(); + expect((await inboxOf(ql, 'u_en'))[0]?.body_md).toBe(enBody('Opportunity')); + expect((await inboxOf(ql, 'u_zh'))[0]?.body_md).toBe(zhBody('商机')); + }); + + it('a renamed packaged object is named by its rename in every language, as /meta names it', async () => { + const ql = await bootDeal('Deal'); + expect(metaLabel(ql, 'en')).toBe('Deal'); + expect(metaLabel(ql, 'zh-CN')).toBe('Deal'); + const c = compose(ql, { i18n: sourceLocaleI18n() }); + await c.messaging.emit(emitDeal(['u_en', 'u_zh'], TYPED)); + expect((await inboxOf(ql, 'u_en'))[0]?.body_md).toBe(enBody('Deal')); + expect((await inboxOf(ql, 'u_zh'))[0]?.body_md).toBe(zhBody('Deal')); + }); + + it("the inbox reader's render resolves it the same way, in the READER's language", async () => { + const ql = await bootDeal(); + const c = compose(ql, { i18n: sourceLocaleI18n(), deploymentDefault: 'zh-CN' }); + expect(installInboxReaderLocale(ql, c.textRenderer!)).toBe(true); + await c.messaging.emit(emitDeal(['u_none'], TYPED)); + const readAs = async (locale: string) => ((await ql.find( + INBOX_OBJECT, { where: { user_id: 'u_none' }, fields: ['body_md'] }, + { context: { userId: 'u_none', locale } as ExecutionContext }, + )) as any[]).map((r) => r.body_md); + expect(await readAs('en')).toEqual([enBody('Opportunity')]); + expect(await readAs('en-US')).toEqual([enBody('Opportunity')]); + expect(await readAs('zh-CN')).toEqual([zhBody('商机')]); + }); + + it('never reads the label through t(): a service that cannot hand its translations over delivers the fallback', async () => { + const ql = await bootDeal(); + const full = sourceLocaleI18n(); + const tOnly = { t: full.t.bind(full), getLocales: full.getLocales.bind(full) }; + const c = compose(ql, { i18n: tOnly as unknown as ReturnType }); + await c.messaging.emit(emitDeal(['u_zh'], TYPED)); + expect((await inboxOf(ql, 'u_zh'))[0]?.body_md).toBe(zhBody('Opportunity')); + }); + + it('the typed param is closed: a malformed one is refused before anything is written', async () => { + const ql = await bootDeal(); + const { messaging } = compose(ql, { i18n: sourceLocaleI18n() }); + const bad: unknown[] = [ + { objectLabel: 'crm_deal' }, // no fallback + { objectLabel: 'crm deal', fallback: 'Deal' }, // not an object's API name + { objectLabel: 'objects.crm_deal.label', fallback: 'Deal' }, // a catalog key is not a name + { objectLabel: 'crm_deal', fallback: 'Deal', key: 'objects.crm_deal.label' }, // both shapes at once + { objectLabel: 7, fallback: 'Deal' }, + ]; + for (const object of bad) { + const keyedText = { ...TYPED, params: { object, record: 'D_1' } }; + await expect(messaging.emit(emitDeal(['u_zh'], keyedText as unknown as NotificationTextKeys)), JSON.stringify(object)) + .rejects.toBeInstanceOf(TypeError); + } + expect(await ql.find(NOTIFICATION_EVENT_OBJECT, { fields: ['id'] }, SYSTEM)).toEqual([]); + }); +}); diff --git a/packages/spec/liveness/translation.json b/packages/spec/liveness/translation.json index f99a92e3ef7..c2a11ac9d69 100644 --- a/packages/spec/liveness/translation.json +++ b/packages/spec/liveness/translation.json @@ -249,9 +249,9 @@ "status": "live", "verifiedAt": "2026-10-21", "evidenceScope": "in-repo", - "evidence": "packages/plugins/plugin-approvals/src/reader-locale-labels.ts#approvalStepLabelKey (spells `flows..approvals..label`, `` the request's `process_name` without its `flow:` prefix and `` its `current_step`); packages/plugins/plugin-approvals/src/reader-locale-labels.ts#readerLabelsFor (asks `II18nService.t()` in the reader's `ExecutionContext.locale`, negotiated by `resolveBundleLocale`; a miss echoes the key and picks nothing); packages/plugins/plugin-approvals/src/reader-locale-labels.ts#localizeRequestLabels (overlays the served `step_label` and `current_step_label` together with the picked label, and keeps the stored snapshot when nothing is picked); packages/plugins/plugin-approvals/src/approval-service.ts#readerLabels (asked by `listRequests`, the inbox and the record's approval panel, and by `loadRequest`, the get and every write's echo); packages/plugins/plugin-approvals/src/approval-service.ts#attachFlowSteps (names each `flow_steps` approval step by the same pick, else the node's authored label)", + "evidence": "packages/plugins/plugin-approvals/src/reader-locale-labels.ts#approvalStepLabelKey (spells `flows..approvals..label`, `` the request's `process_name` without its `flow:` prefix and `` its `current_step`); packages/spec/src/system/i18n-resolver.ts#resolveFlowApprovalStepLabel (the spec's one reading of the key: walks the locale chain of `ResolveOptions` over the bundle, the requested locale then the DECLARED fallback chain unless the requested locale is the authored one, and answers the literal, here none, on a miss); packages/plugins/plugin-approvals/src/reader-locale-labels.ts#readerLabelsFor (asks that resolver over every locale the `i18n` service holds, with the metadata route's resolve options: the reader's `ExecutionContext.locale` negotiated by `resolveBundleLocale`, the declared fallback locale, and the declared `sourceLocale` else `defaultLocale`; a miss picks nothing); packages/plugins/plugin-approvals/src/reader-locale-labels.ts#localizeRequestLabels (overlays the served `step_label` and `current_step_label` together with the picked label, and keeps the stored snapshot when nothing is picked); packages/plugins/plugin-approvals/src/approval-service.ts#readerLabels (asked by `listRequests`, the inbox and the record's approval panel, and by `loadRequest`, the get and every write's echo); packages/plugins/plugin-approvals/src/approval-service.ts#attachFlowSteps (names each `flow_steps` approval step by the same pick, else the node's authored label)", "producer": "packages/runtime/src/app-plugin.ts#loadTranslations (hands each bundle's locale data to the i18n service whole, `flows` included); packages/plugins/plugin-approvals/src/approvals-plugin.ts#i18nServiceSource (the approvals service's lazy reader of that service); packages/plugins/plugin-approvals/src/approval-service.ts#openNodeRequest (snapshots the node's authored `label` onto `sys_approval_request.current_step_label` when the request opens: the text a reader is served when nothing is picked)", - "note": "Overlays the `approval` node's own `FlowNode.label`, the step name an approval request shows. FLIPPED planned → live 2026-10-21 with its container `flows.approvals` (see that row), reader landed in ba69b168be. A read, never a write: the stored `current_step_label` stays the authored snapshot (the audit record, and what the generic data door and list views serve). Nothing is picked when the read carries no locale (a system context, the token-bearing action page), when no `i18n` service is registered, when the pack holds no entry, or when the service throws. Pinned end to end by packages/plugins/plugin-approvals/src/reader-locale-display-labels.integration.test.ts, and the key spelling is held to `TranslationDataSchema` by packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts." + "note": "Overlays the `approval` node's own `FlowNode.label`, the step name an approval request shows. FLIPPED planned → live 2026-10-21 with its container `flows.approvals` (see that row), reader landed in ba69b168be. A read, never a write: the stored `current_step_label` stays the authored snapshot (the audit record, and what the generic data door and list views serve). Nothing is picked when the read carries no locale (a system context, the token-bearing action page), when no `i18n` service is registered, when the pack holds no entry, or when the service throws. [#35384] Since 2026-11-23 the reader asks the spec resolver, not `II18nService.t()`, so a reader in a deployment's declared `sourceLocale` reads the authored step label, never the `defaultLocale` row `t()` falls back to. Pinned end to end by packages/plugins/plugin-approvals/src/reader-locale-display-labels.integration.test.ts, and the key spelling is held to `TranslationDataSchema` by packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts." } } }, From 9d5362af66a0a1c422143d3444bbde9309fa3210 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 03:07:57 +0000 Subject: [PATCH 3/5] chore(spec): regenerate the api-surface and export-origins snapshots for the new resolver Claude-Session: https://claude.ai/code/session_01ADHkmQNmyLgnBbCoc2iFjL Co-authored-by: Claude --- packages/spec/api-surface/system.json | 1 + packages/spec/export-origins/system.json | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/spec/api-surface/system.json b/packages/spec/api-surface/system.json index 6fe4a23d9c5..588c3b5a96b 100644 --- a/packages/spec/api-surface/system.json +++ b/packages/spec/api-surface/system.json @@ -911,6 +911,7 @@ "resolveBundleLocale (function)", "resolveDocAudiences (function)", "resolveDocLocale (function)", + "resolveFlowApprovalStepLabel (function)", "resolveFlowScreenFieldOptions (function)", "resolveFlowScreenTitle (function)", "resolveLocaleAmong (function)", diff --git a/packages/spec/export-origins/system.json b/packages/spec/export-origins/system.json index 4b47e36a0af..5693886471c 100644 --- a/packages/spec/export-origins/system.json +++ b/packages/spec/export-origins/system.json @@ -871,6 +871,7 @@ "resolveBundleLocale": "src/system/i18n-resolver.ts#resolveBundleLocale (function)", "resolveDocAudiences": "src/system/book.zod.ts#resolveDocAudiences (function)", "resolveDocLocale": "src/system/doc.zod.ts#resolveDocLocale (function)", + "resolveFlowApprovalStepLabel": "src/system/i18n-resolver.ts#resolveFlowApprovalStepLabel (function)", "resolveFlowScreenFieldOptions": "src/system/i18n-resolver.ts#resolveFlowScreenFieldOptions (function)", "resolveFlowScreenTitle": "src/system/i18n-resolver.ts#resolveFlowScreenTitle (function)", "resolveLocaleAmong": "src/system/i18n-resolver.ts#resolveLocaleAmong (function)", From 2dfa8720abc41d7e2ef2dd45cbfdef7c58071ef8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 03:10:18 +0000 Subject: [PATCH 4/5] test(approvals): the no-approver note's test renderer reads the typed object-label param Claude-Session: https://claude.ai/code/session_01ADHkmQNmyLgnBbCoc2iFjL Co-authored-by: Claude --- packages/plugins/plugin-approvals/src/no-approver-note.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/plugins/plugin-approvals/src/no-approver-note.test.ts b/packages/plugins/plugin-approvals/src/no-approver-note.test.ts index 6303bd562b2..c60047c8a67 100644 --- a/packages/plugins/plugin-approvals/src/no-approver-note.test.ts +++ b/packages/plugins/plugin-approvals/src/no-approver-note.test.ts @@ -42,6 +42,8 @@ const deliveredIn = ( const params: Record = {}; for (const [name, param] of Object.entries(notice.params)) { if (typeof param === 'string') { params[name] = param; continue; } + // [#35384] An object-label param is resolved off the object's metadata, which no notice here names. + if ('objectLabel' in param) { params[name] = param.fallback; continue; } const looked = param.key.startsWith('messages.') ? catalog[param.key.slice('messages.'.length)] : pack[param.key]; params[name] = looked ?? param.fallback; } From cfce553f641ece82053a0eb1997a8958accecdd2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 04:07:17 +0000 Subject: [PATCH 5/5] refactor(messaging): name the object-label param's member object, the object's API name it holds Claude-Session: https://claude.ai/code/session_01ADHkmQNmyLgnBbCoc2iFjL Co-authored-by: Claude --- ...tep-label-and-notification-object-label.md | 2 +- ...otification-keyed-text.integration.test.ts | 2 +- .../src/approval-notification-text.ts | 7 +++-- .../src/no-approver-note.test.ts | 2 +- ...eyed-notification-text.integration.test.ts | 14 ++++----- .../src/notification-text.ts | 29 ++++++++++--------- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/.changeset/35384-step-label-and-notification-object-label.md b/.changeset/35384-step-label-and-notification-object-label.md index 02afc5c4c6f..df5c590e17b 100644 --- a/.changeset/35384-step-label-and-notification-object-label.md +++ b/.changeset/35384-step-label-and-notification-object-label.md @@ -12,7 +12,7 @@ Metadata-protocol: none In a deployment whose `i18n.sourceLocale` differs from its `i18n.defaultLocale` (an app authored in English that defaults its users to Chinese), an English reader was shown the Chinese approval step name, and an English approval-notification recipient read the Chinese object name inside an English sentence. Both labels were read through `II18nService.t()`, which falls back to the `defaultLocale` row; `/meta` serves the authored text. Both now resolve the way the metadata route resolves a label: the reader's negotiated locale, the declared fallback chain, and the authored language (the declared `sourceLocale`, else `defaultLocale`). - **`@objectstack/spec`** adds `resolveFlowApprovalStepLabel(bundle, flowName, nodeId, literal?, opts?)` (`@objectstack/spec/system`), the one reading of `flows..approvals..label`: the requested locale, then the declared fallback chain (skipped for the authored locale), then `literal`. It takes the flow's name and the node's id, so a reader holding only an approval request row needs no flow document. -- **`@objectstack/service-messaging`** accepts a new `NotificationTextKeys.params` value, `{ objectLabel: '', fallback }` (`NotificationObjectLabelParam`): the label of that object in the recipient's language, resolved as `GET /meta/object/:name` serves it, by `translateObject` over the object's served definition and its packaged base, so a renamed packaged object is named by its rename. It renders the same way on the inline fan-out, the dispatcher (digests included) and the inbox reader. `fallback` is delivered when nothing resolves. The `{ key, fallback }` value is still accepted and still renders through `t()`, so stored deliveries and inbox rows render as before. +- **`@objectstack/service-messaging`** accepts a new `NotificationTextKeys.params` value, `{ object: '', fallback }` (`NotificationObjectLabelParam`): the label of that object in the recipient's language, resolved as `GET /meta/object/:name` serves it, by `translateObject` over the object's served definition and its packaged base, so a renamed packaged object is named by its rename. It renders the same way on the inline fan-out, the dispatcher (digests included) and the inbox reader. `fallback` is delivered when nothing resolves. The `{ key, fallback }` value is still accepted and still renders through `t()`, so stored deliveries and inbox rows render as before. - **`@objectstack/plugin-approvals`** names a notification's object with that typed param, and reads the approval step label through `resolveFlowApprovalStepLabel`, so `t()` carries catalog sentences only. Upgrade `@objectstack/plugin-approvals` and `@objectstack/service-messaging` together: an older messaging service refuses the typed param at `emit()`. diff --git a/packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts b/packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts index 7fe9128d913..8c686940119 100644 --- a/packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts +++ b/packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts @@ -365,7 +365,7 @@ describe('#24978 — end to end: a real messaging service renders each approver\ /** * [#35384] The object an approval notification names is labelled as * `GET /meta/object/:name` serves it: the subject param is the messaging - * service's typed object-label param (`{ objectLabel, fallback }`), resolved + * service's typed object-label param (`{ object, fallback }`), resolved * per recipient by `translateObject` with the metadata route's resolve options * and the object's packaged base, never through `t()`. * diff --git a/packages/plugins/plugin-approvals/src/approval-notification-text.ts b/packages/plugins/plugin-approvals/src/approval-notification-text.ts index ebcb370aa6b..8609f9063a4 100644 --- a/packages/plugins/plugin-approvals/src/approval-notification-text.ts +++ b/packages/plugins/plugin-approvals/src/approval-notification-text.ts @@ -32,7 +32,7 @@ * (`ApprovalService.notify` resolves it per recipient); the #23556 / #23594 * ruling B form, label and id for every reader, stands only on the * reader-less action-link pages. [#35384] The label rides as the messaging - * service's typed object-label param, `{ objectLabel: , fallback }`, + * service's typed object-label param, `{ object: , fallback }`, * which it resolves per recipient as `GET /meta/object/:name` serves the * object (`translateObject` with the metadata route's resolve options and the * packaged base), the way the reader-language labels (`reader-locale-labels.ts`) @@ -55,7 +55,8 @@ export type ApprovalTextParam = /** [#35384] The structural mirror of the messaging service's `NotificationObjectLabelParam`. */ export interface ApprovalObjectLabelParam { - readonly objectLabel: string; + /** The object's API name, never its label. */ + readonly object: string; readonly fallback: string; } @@ -105,7 +106,7 @@ export function subjectParams( record: string, ): ApprovalSubjectParams { return { - object: { objectLabel: objectName, fallback: objectLabel ?? objectName }, + object: { object: objectName, fallback: objectLabel ?? objectName }, record, }; } diff --git a/packages/plugins/plugin-approvals/src/no-approver-note.test.ts b/packages/plugins/plugin-approvals/src/no-approver-note.test.ts index c60047c8a67..490b31db63a 100644 --- a/packages/plugins/plugin-approvals/src/no-approver-note.test.ts +++ b/packages/plugins/plugin-approvals/src/no-approver-note.test.ts @@ -43,7 +43,7 @@ const deliveredIn = ( for (const [name, param] of Object.entries(notice.params)) { if (typeof param === 'string') { params[name] = param; continue; } // [#35384] An object-label param is resolved off the object's metadata, which no notice here names. - if ('objectLabel' in param) { params[name] = param.fallback; continue; } + if ('object' in param) { params[name] = param.fallback; continue; } const looked = param.key.startsWith('messages.') ? catalog[param.key.slice('messages.'.length)] : pack[param.key]; params[name] = looked ?? param.fallback; } diff --git a/packages/services/service-messaging/src/keyed-notification-text.integration.test.ts b/packages/services/service-messaging/src/keyed-notification-text.integration.test.ts index aa314d29cee..02ad1161a77 100644 --- a/packages/services/service-messaging/src/keyed-notification-text.integration.test.ts +++ b/packages/services/service-messaging/src/keyed-notification-text.integration.test.ts @@ -725,7 +725,7 @@ describe("#32240 — an inbox row reads in the READER's language", () => { }); /** - * [#35384] The typed object-label param, `{ objectLabel, fallback }`: an + * [#35384] The typed object-label param, `{ object, fallback }`: an * object's label is METADATA, so it is resolved as `GET /meta/object/:name` * serves it — `translateObject` over the object's served definition and its * packaged base, with the metadata route's resolve options (the recipient's @@ -751,7 +751,7 @@ describe('#35384 — an object label param reads as /meta serves the object', () const TYPED: NotificationTextKeys = { titleKey: 'messages.dealTitle', bodyKey: 'messages.dealBody', - params: { object: { objectLabel: 'crm_deal', fallback: 'Opportunity' }, record: 'D_1' }, + params: { object: { object: 'crm_deal', fallback: 'Opportunity' }, record: 'D_1' }, }; const LEGACY: NotificationTextKeys = { ...TYPED, @@ -866,11 +866,11 @@ describe('#35384 — an object label param reads as /meta serves the object', () const ql = await bootDeal(); const { messaging } = compose(ql, { i18n: sourceLocaleI18n() }); const bad: unknown[] = [ - { objectLabel: 'crm_deal' }, // no fallback - { objectLabel: 'crm deal', fallback: 'Deal' }, // not an object's API name - { objectLabel: 'objects.crm_deal.label', fallback: 'Deal' }, // a catalog key is not a name - { objectLabel: 'crm_deal', fallback: 'Deal', key: 'objects.crm_deal.label' }, // both shapes at once - { objectLabel: 7, fallback: 'Deal' }, + { object: 'crm_deal' }, // no fallback + { object: 'crm deal', fallback: 'Deal' }, // not an object's API name + { object: 'objects.crm_deal.label', fallback: 'Deal' }, // a catalog key is not a name + { object: 'crm_deal', fallback: 'Deal', key: 'objects.crm_deal.label' }, // both shapes at once + { object: 7, fallback: 'Deal' }, ]; for (const object of bad) { const keyedText = { ...TYPED, params: { object, record: 'D_1' } }; diff --git a/packages/services/service-messaging/src/notification-text.ts b/packages/services/service-messaging/src/notification-text.ts index bca50ef6a99..8037d9c870b 100644 --- a/packages/services/service-messaging/src/notification-text.ts +++ b/packages/services/service-messaging/src/notification-text.ts @@ -27,10 +27,10 @@ * - `params` fills the entries' `{{name}}` holes. A value is used as given, * or, spelled `{ key, fallback }`, is itself the recipient-language text of * the catalog entry `key`, else `fallback`; or, spelled - * `{ objectLabel, fallback }`, is the label of the object named - * `objectLabel` in the recipient's language, else `fallback`. + * `{ object, fallback }`, is the label of the object whose API name is + * `object`, in the recipient's language, else `fallback`. * - [#35384] An object's label is METADATA, not a catalog sentence, so the - * `{ objectLabel }` param is resolved as `GET /meta/object/:name` serves it: + * `{ object }` param is resolved as `GET /meta/object/:name` serves it: * by `translateObject` (`@objectstack/spec/system`) over the object's * served definition and its packaged base, with the metadata route's * `ResolveOptions` (the recipient's negotiated locale, the DECLARED @@ -98,15 +98,16 @@ export type NotificationTextParam = | NotificationObjectLabelParam; /** - * [#35384] A `{{name}}` value that is the label of the object `objectLabel` - * names (its API name, `crm_deal`), in the recipient's language, as + * [#35384] A `{{name}}` value that is the label of the object whose API name + * `object` holds (`crm_deal`), in the recipient's language, as * `GET /meta/object/:name` serves it: `translateObject` over the object's * served definition and packaged base, with the metadata route's resolve * options. `fallback` is the text when nothing resolves (no `i18n` service * that can hand its translations over, no data engine that knows the object). */ export interface NotificationObjectLabelParam { - readonly objectLabel: string; + /** The object's API name (`ObjectSchema.name`), never its label: the param names the object, the render picks its label. */ + readonly object: string; readonly fallback: string; } @@ -158,7 +159,7 @@ const PARAM_NAME_SHAPE = /^\w+$/; const TEXT_MEMBERS: ReadonlySet = new Set(['titleKey', 'bodyKey', 'params']); const KEYED_PARAM_MEMBERS: ReadonlySet = new Set(['key', 'fallback']); -const OBJECT_LABEL_PARAM_MEMBERS: ReadonlySet = new Set(['objectLabel', 'fallback']); +const OBJECT_LABEL_PARAM_MEMBERS: ReadonlySet = new Set(['object', 'fallback']); /** * An object's API name: one segment of {@link CATALOG_KEY_SHAPE}, so every @@ -194,15 +195,15 @@ function problemOf(value: unknown): string | undefined { for (const [name, param] of Object.entries(params)) { if (!PARAM_NAME_SHAPE.test(name)) return `.params has a name '${name}' no {{hole}} can spell`; if (typeof param === 'string') continue; - if (!isPlainObject(param)) return `.params.${name} must be a string, { key, fallback } or { objectLabel, fallback }`; - if ('objectLabel' in param) { + if (!isPlainObject(param)) return `.params.${name} must be a string, { key, fallback } or { object, fallback }`; + if ('object' in param) { for (const member of Object.keys(param)) { if (!OBJECT_LABEL_PARAM_MEMBERS.has(member)) { - return `.params.${name} has an undeclared member '${member}' (declared: objectLabel, fallback)`; + return `.params.${name} has an undeclared member '${member}' (declared: object, fallback)`; } } - if (typeof param.objectLabel !== 'string' || !OBJECT_NAME_SHAPE.test(param.objectLabel)) { - return `.params.${name}.objectLabel must be an object's API name such as 'crm_deal' (got ${JSON.stringify(param.objectLabel)})`; + if (typeof param.object !== 'string' || !OBJECT_NAME_SHAPE.test(param.object)) { + return `.params.${name}.object must be an object's API name such as 'crm_deal' (got ${JSON.stringify(param.object)})`; } if (typeof param.fallback !== 'string') return `.params.${name}.fallback must be a string`; continue; @@ -375,9 +376,9 @@ export class NotificationTextRenderer { for (const [name, param] of Object.entries(keys.params ?? {})) { if (typeof param === 'string') { params[name] = param; - } else if ('objectLabel' in param) { + } else if ('object' in param) { translation ??= { value: metaLabelTranslation(i18n, locale) }; - params[name] = this.objectLabel(translation.value, param.objectLabel) ?? param.fallback; + params[name] = this.objectLabel(translation.value, param.object) ?? param.fallback; } else { params[name] = lookup(i18n, param.key, locale) ?? param.fallback; }