Skip to content

Commit 99ece3c

Browse files
fix(i18n): approval step label and approval notification object label read as /meta serves them (#36620)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9DD8XEF1VwrqXiQzo8zQCjY)_ Fixes #35384 Clause-②: yes (widening) Metadata-protocol: none Skills-docs: none — Metadata-protocol is none and there is no (narrowing) arm; no skills/** file teaches either label reading ## 维护者速读 - 用户能看到什么变化:在「编写语言与默认语言不同」的部署里(例如英文编写、用户默认中文),英文读者在审批收件箱和审批页上看到的审批步骤名,以及英文收件人收到的审批通知里的对象名,改为作者原文,不再混入中文;对象在代码里改过名的,通知里显示新名。 - 为什么做:这是「审批与审计文案按元数据接口同一方式取标签」那张卡的最后两项,前两批已合并,本次合并后该卡关闭。 - 出错会怎样:只影响审批步骤名和通知里的对象名这两处显示文字,取不到时退回原先存下的文字,不会让审批或通知失败;改动可整体撤回,已存的通知照旧显示。 - 要你做什么:无。 ## What changes The rule this card carries (from #34030): "resolve the label through `translateObject` with the same resolve options `/meta` builds, so `t()` carries messages only". This PR delivers the card's two remaining items (items 2 and 3 landed in #36464 and #36598). **1. Approval notification object label (service-messaging, plugin-approvals).** - `NotificationTextKeys.params` accepts a new value, `{ object: 'OBJECT_API_NAME', fallback }` (`NotificationObjectLabelParam`, exported from `@objectstack/service-messaging`). `renderWith` resolves it through `translateObject` (`@objectstack/spec/system`) over the object's served definition (`getSchema`) and its packaged base (`registry.getPackagedObjectBase`), both read off the data engine the renderer already holds. The resolve options are `/meta`'s: the recipient's negotiated locale, the declared fallback chain, and the declared `sourceLocale` else `defaultLocale`, inlined as `reader-locale-labels.ts` does (one exported builder is #36467). `fallback` is delivered when nothing resolves. - The inline fan-out, the dispatcher (claimed rows and digests) and the inbox reader (`renderForReader`) all go through `renderWith`, so all four paths resolve the label the same way. - Widening, not replacement: `{ key, fallback }` is still accepted and still renders through `t()`, so stored outbox and inbox rows render exactly as before. The closed-shape validator (`problemOf`) admits the new shape and refuses a mixed one, a missing `fallback`, or a name that is not an object API name. The name shape is one segment of the existing catalog-key shape, so every object a `{ key: 'objects.OBJECT.label' }` param could name, the typed param can name too. - plugin-approvals `subjectParams` now emits `{ object: objectName, fallback }`. **2. Approval step label (spec, plugin-approvals).** - New spec export `resolveFlowApprovalStepLabel(bundle, flowName, nodeId, literal?, opts?)` in `packages/spec/src/system/i18n-resolver.ts`. It is the one reading of `flows.FLOW.approvals.NODE_ID.label`, using the same locale chain and the same bundle-then-literal order as `resolveFlowScreenTitle`. - `reader-locale-labels.ts` `stepLabel` resolves through it with the `/meta` resolve options it already builds for the flow, object and position labels. No key is asked of `t()` any more. - `translateFlow` is unchanged and stays unregistered in `translateMetadataDocument`. - Liveness `flows.approvals.label` evidence is re-anchored on the spec resolver. ### Export choice (seat ruling, premise measured) The seat ruled: overlay the step label inside `translateFlow` if the step-label read points already hold or read the flow document; otherwise use `resolveFlowApprovalStepLabel`. Measured at `aff34baea`: - `reader-locale-labels.ts:405-410` (`localizeRequestLabels`) has only `process_name` and `current_step` from the stored row. No flow document is in hand. It is called for every row of a list read (`approval-service.ts:10921`, `listRequests`), for the single read (`:11205`), and by the generic data door (`reader-locale-labels-middleware.ts:104`). Getting a document there would add one flow read per row. - `flowLabel` (`reader-locale-labels.ts:359`) does not read the flow document. It hands `translateFlow` a stub, `{ name: flowName }`. So do the other `translateFlow` callers in the tree: `ui/packages/app-shell/src/views/FlowRunner.tsx:445` and `ui/packages/plugin-detail/src/stageChangeStarts.tsx:106` both pass `{ name, label }`. - Only the single-read enrichment holds the document (`approval-service.ts:11340` `requestFlow`, used by `attachFlowSteps` `:11350` and `attachFlowRoute` `:11407`). The premise does not hold at the main read point, so this PR takes `resolveFlowApprovalStepLabel`. `translateFlow` and its docblock are untouched, so no client-visible change. The param's member is `object`, by seat ruling (card comment 7091274184), and the type name stays `NotificationObjectLabelParam`. Three reasons: - The member holds the object's API name, not a label. - In the spec, the word `object` always means an object's API name. - The sibling `{ key, fallback }` is also named for what it holds. The first round built it as `objectLabel` and round 2 renamed it. The mixed shape `{ object, fallback, key }` is still refused. ### Tests changed (forced) - `plugin-approvals/src/reader-locale-labels.test.ts`: two pins that drove the step label through a `t()`-only double were re-triaged onto `getTranslations`. One is "negotiates through `resolveBundleLocale`…" and the other is "asks the service once per read, and never through t()". The `#35384` flow/position sourceLocale describe now also covers the step label. - `plugin-approvals/src/no-approver-note.test.ts`: its local renderer narrows the widened `ApprovalTextParam` union. TS2339 came from `check:test-typecheck`, and no assertion changed. ## Tests <details><summary>Readings</summary> - New pins: spec `i18n-resolver.test.ts` describe `resolveFlowApprovalStepLabel` (5 cases: locale + `zh` ladder, declared chain, authored locale sourceLocale en / default zh-CN, literal and empty-bundle fallbacks, own keys). service-messaging `keyed-notification-text.integration.test.ts` describe `#35384` (7 cases on a real ObjectQL + SqlDriver: precondition, inline fan-out, SQL outbox + dispatcher, renamed packaged object with `/meta`'s `translateMetadataDocument` as oracle, inbox reader en / en-US / zh-CN, `t()`-only service, closed shape). plugin-approvals `approval-notification-keyed-text.integration.test.ts` describe `[#35384]` (real ApprovalService plus real MessagingService: an en approver reads `Deal`, a zh-CN approver reads `商机`, a renamed object reads its rename). - Full suites on `2dfa8720` (the code head; the later merge of `origin/main` touched no file in these packages): `@objectstack/service-messaging` Test Files 80 passed (80), Tests 1084 passed (1084); `@objectstack/plugin-approvals` Test Files 127 passed (127), Tests 1883 passed (1883); `@objectstack/spec` (on `9d5362af`, spec unchanged after) Test Files 880 passed (880), Tests 28058 passed, 1 todo. Typecheck of all three packages, including spec's `check:test-typecheck` and approvals' `check:test-typecheck`: exit 0. - Round 2, the rename of the member to `object`, at `cfce553f`: `pnpm exec turbo run build` of both closures (40/40 tasks), then the typecheck of service-messaging and plugin-approvals (including `check:test-typecheck`) exited 0. `@objectstack/service-messaging` Test Files 80 passed (80), Tests 1084 passed (1084). `@objectstack/plugin-approvals` Test Files 127 passed (127), Tests 1883 passed (1883). The closed-shape pin still refuses `{ object, fallback, key }`. Spec is unchanged in round 2. - Ablation (round 1; one lock call each, `scripts/ablation-replace.mjs` plus a trap restore; every subject resolves from `src/`, so there is no dist leg; each leg's anchor went x1 to x0 and was restored with blob equal to HEAD and `git diff HEAD` empty): - Leg 1a, messaging object label read through `t()`: 5 failed / 7 of the `#35384` describe. - Leg 1b, no `packagedBase`: 1 failed / 7 (the rename case). The first attempt was refused by the tool as a no-op (the replacement text already existed elsewhere), so it was re-run with a distinct replacement. - Leg 2, approvals `stepLabel` back on `t()`: 5 failed / 37. - Leg 3, spec resolver walking the declared chain for the authored locale: 1 failed / 5. - Leg 4, approvals `subjectParams` back to `{ key }`: 2 failed / 8 (both end-to-end `[#35384]` cases). </details> ## Acceptance notes - Version skew: an older `service-messaging` refuses `{ object, fallback }` at `emit()`. Both packages are in the changeset `fixed` group, and the changeset says to upgrade them together. - A `t()`-only i18n double (no `getTranslations`) now gets the `fallback` for the typed param, not the `t()` row. `II18nService.getTranslations` is a required member, so every served service hands its translations over. - Other producers that name an object through `{ key: 'objects.OBJECT.label' }` keep the `t()` reading until they adopt the typed param. Only plugin-approvals emits it today (`git grep objectLabelKey` under packages/services and packages/plugins). - CI on the round-1 head `0b91c34b`: Test UI, Lint & Repo Gates and TypeScript Type Check read red, and none of them is a test or type failure. Run 45109434849 concluded `cancelled` at 04:07:57Z because the push of `cfce553f` (committed 04:07:17Z; its CI run 45109928513 was created at 04:07:32Z) superseded it. Every Test UI, Test Core, Lint and Type Check lane on `0b91c34b` concluded `cancelled` between 04:07:33Z and 04:07:57Z. The three rollups only report that: Test UI logged "the Test UI shards concluded 'cancelled'", Lint & Repo Gates logged "lint lane ... concluded `cancelled`" for four lanes, and TypeScript Type Check logged "type-check lane ... concluded `cancelled`" for three lanes, with no `error TS` line. Nothing under `ui/**` or `examples/**` consumes `NotificationTextParam`, `ApprovalTextParam` or the stored `keyed_text` (`git grep`). The only in-repo narrowing site was `no-approver-note.test.ts`, fixed in round 1. ## Verification Read first: `packages/services/service-messaging/src/notification-text.ts` (`renderWith` and the private `objectLabel` resolver; risk: the validator's new branch), `packages/spec/src/system/i18n-resolver.ts` (`resolveFlowApprovalStepLabel`), `packages/plugins/plugin-approvals/src/reader-locale-labels.ts` (`stepLabel`). Two-minute check: `pnpm --filter @objectstack/service-messaging exec vitest run src/keyed-notification-text.integration.test.ts -t 35384` should show 7 passed. The en recipient reads `Your Opportunity D_1 awaits approval.`, and the renamed object reads `Deal`. https://claude.ai/code/session_01ADHkmQNmyLgnBbCoc2iFjL 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmQNmyLgnBbCoc2iFjL --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9e2a4ac commit 99ece3c

14 files changed

Lines changed: 654 additions & 53 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/service-messaging': patch
4+
'@objectstack/plugin-approvals': patch
5+
---
6+
7+
fix(i18n): an approval step label and an approval notification's object label read as the metadata translators serve them
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
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`).
13+
14+
- **`@objectstack/spec`** adds `resolveFlowApprovalStepLabel(bundle, flowName, nodeId, literal?, opts?)` (`@objectstack/spec/system`), the one reading of `flows.<flow>.approvals.<node_id>.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.
15+
- **`@objectstack/service-messaging`** accepts a new `NotificationTextKeys.params` value, `{ object: '<object API name>', 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.
16+
- **`@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.
17+
18+
Upgrade `@objectstack/plugin-approvals` and `@objectstack/service-messaging` together: an older messaging service refuses the typed param at `emit()`.

‎packages/plugins/plugin-approvals/src/approval-notification-keyed-text.integration.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,81 @@ describe('#24978 — end to end: a real messaging service renders each approver\
361361
]);
362362
});
363363
});
364+
365+
/**
366+
* [#35384] The object an approval notification names is labelled as
367+
* `GET /meta/object/:name` serves it: the subject param is the messaging
368+
* service's typed object-label param (`{ object, fallback }`), resolved
369+
* per recipient by `translateObject` with the metadata route's resolve options
370+
* and the object's packaged base, never through `t()`.
371+
*
372+
* The deployment: authored in English (`sourceLocale: 'en'`), defaulting its
373+
* users to Chinese (`defaultLocale` and the declared fallback `zh-CN`), with a
374+
* `zh-CN` pack for the object. `t('objects.crm_deal.label', 'en')` falls to the
375+
* `zh-CN` row, so before this an English approver read `商机` inside an
376+
* English sentence. CONTROL: the Chinese approver still reads `商机`.
377+
*/
378+
describe('[#35384] the object an approval notification names reads as /meta serves it', () => {
379+
/** The en-authored, zh-CN-default deployment's i18n service. */
380+
const sourceLocaleI18n = () => {
381+
const i18n = i18nWithBundle('zh-CN');
382+
i18n.setFallbackLocale('zh-CN');
383+
i18n.setSourceLocale('en');
384+
// The served adapter's shape (`FileI18nAdapter`): the declared fallback, read back.
385+
return Object.assign(i18n, { getFallbackLocale: () => 'zh-CN' });
386+
};
387+
388+
/** Open one request on a fresh engine; `rename` extends the packaged `Deal` into a new label first. */
389+
const openOn = async (rename?: string) => {
390+
const engine = await bootEngine([
391+
{ id: 'u_sub', name: 'Sun Submitter', email: 'sun@example.com', locale: 'zh-CN' },
392+
{ id: 'u_zh', name: 'Zhang', email: 'zhang@example.com', locale: 'zh-CN' },
393+
{ id: 'u_en', name: 'Ada', email: 'ada@example.com', locale: 'en' },
394+
]);
395+
try {
396+
if (rename) engine.registry.registerObjectExtension({ extend: 'crm_deal', label: rename } as never, 'com.acme.crm.custom');
397+
const i18n = sourceLocaleI18n();
398+
const getData = () => engine as any;
399+
const messaging = new MessagingService({
400+
logger: silent,
401+
getData,
402+
textRenderer: new NotificationTextRenderer({
403+
getData, getI18n: () => i18n, getDefaultLocale: () => i18n.getDefaultLocale(), logger: silent,
404+
}),
405+
});
406+
messaging.registerChannel(createInboxChannel({ getData }));
407+
let now = Date.parse('2026-10-01T09:00:00.000Z');
408+
const svc = approvalService(engine, () => new Date(now += 1000));
409+
svc.attachMessaging(messaging as any);
410+
await engine.insert('crm_deal', { id: 'D_1', title: 'Big deal', organization_id: ORG }, { context: SYSTEM } as any);
411+
await svc.openNodeRequest({
412+
object: 'crm_deal', recordId: 'D_1', runId: 'run_1', nodeId: 'review', flowName: FLOW.name,
413+
config: { approvers: [{ type: 'user', value: 'u_zh' }, { type: 'user', value: 'u_en' }], behavior: 'first_response' } as any,
414+
submitterId: 'u_sub', record: { id: 'D_1', title: 'Big deal' },
415+
}, asUser('u_sub'));
416+
const bodyOf = async (userId: string) => {
417+
const rows = (await engine.find('sys_inbox_message', { where: { user_id: userId }, fields: ['body_md'] }, { context: SYSTEM })) as any[];
418+
return rows.map((r) => r.body_md);
419+
};
420+
return { en: await bodyOf('u_en'), zh: await bodyOf('u_zh'), i18n };
421+
} finally {
422+
try { await engine.destroy(); } catch { /* noop */ }
423+
}
424+
};
425+
426+
it("the defect's precondition: t() answers an en reader with the zh-CN row", () => {
427+
expect(sourceLocaleI18n().t('objects.crm_deal.label', 'en')).toBe('商机');
428+
});
429+
430+
it('an en approver reads the authored label; CONTROL: a zh-CN approver reads the zh-CN row', async () => {
431+
const { en, zh } = await openOn();
432+
expect(en).toEqual(['A decision on Deal Big deal is waiting on you.']);
433+
expect(zh).toEqual(['商机 Big deal 正在等待您的审批决定。']);
434+
});
435+
436+
it('a renamed packaged object is named by its rename, in every language, as /meta names it', async () => {
437+
const { en, zh } = await openOn('Opportunity');
438+
expect(en).toEqual(['A decision on Opportunity Big deal is waiting on you.']);
439+
expect(zh).toEqual(['Opportunity Big deal 正在等待您的审批决定。']);
440+
});
441+
});

‎packages/plugins/plugin-approvals/src/approval-notification-text.ts‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,34 @@
3131
* the one recipient the text is built for may read it, else the record id
3232
* (`ApprovalService.notify` resolves it per recipient); the #23556 / #23594
3333
* ruling B form, label and id for every reader, stands only on the
34-
* reader-less action-link pages. The label rides as a keyed param — `objects.<object>.label`, the key the reader-language
35-
* labels (`reader-locale-labels.ts`) and objectql's refusals name an object
36-
* by — so a recipient whose language pack holds it reads it in their language;
37-
* the schema label (the API name when there is none) stands otherwise.
34+
* reader-less action-link pages. [#35384] The label rides as the messaging
35+
* service's typed object-label param, `{ object: <object API name>, fallback }`,
36+
* which it resolves per recipient as `GET /meta/object/:name` serves the
37+
* object (`translateObject` with the metadata route's resolve options and the
38+
* packaged base), the way the reader-language labels (`reader-locale-labels.ts`)
39+
* name an object; so a recipient in the deployment's `sourceLocale` reads the
40+
* authored label, a renamed packaged object its rename, and the schema label
41+
* (the API name when there is none) stands when nothing resolves.
3842
*/
3943

40-
import { objectLabelKey } from '@objectstack/spec/system';
4144
import { enMessages, type ApprovalMessageId } from './translations/messages.js';
4245

43-
/** One `{{hole}}` value: the text itself, or a catalog key with the text it falls back to. */
44-
export type ApprovalTextParam = string | { readonly key: string; readonly fallback: string };
46+
/**
47+
* One `{{hole}}` value: the text itself, a catalog key with the text it falls
48+
* back to, or [#35384] an object's label by the object's name with the text it
49+
* falls back to (the messaging service's `NotificationObjectLabelParam`).
50+
*/
51+
export type ApprovalTextParam =
52+
| string
53+
| { readonly key: string; readonly fallback: string }
54+
| ApprovalObjectLabelParam;
55+
56+
/** [#35384] The structural mirror of the messaging service's `NotificationObjectLabelParam`. */
57+
export interface ApprovalObjectLabelParam {
58+
/** The object's API name, never its label. */
59+
readonly object: string;
60+
readonly fallback: string;
61+
}
4562

4663
/**
4764
* The keyed half — the structural mirror of the messaging service's
@@ -68,7 +85,7 @@ export interface ApprovalNotificationText {
6885
* not an interface, so it spreads into a sentence's params as it stands.
6986
*/
7087
export type ApprovalSubjectParams = {
71-
readonly object: { readonly key: string; readonly fallback: string };
88+
readonly object: ApprovalObjectLabelParam;
7289
readonly record: string;
7390
};
7491

@@ -78,9 +95,9 @@ export function approvalMessageKey(id: ApprovalMessageId): string {
7895
}
7996

8097
/**
81-
* The record of `objectName` a notification names: the object's label — keyed
82-
* by `objects.<object>.label`, falling back to `objectLabel` (the schema
83-
* label), else the API name — and `record`, the name its recipient reads for
98+
* The record of `objectName` a notification names: the object's label — the
99+
* typed object-label param naming `objectName`, falling back to `objectLabel`
100+
* (the schema label), else the API name — and `record`, the name its recipient reads for
84101
* it (its title as they may read it, else its id).
85102
*/
86103
export function subjectParams(
@@ -89,7 +106,7 @@ export function subjectParams(
89106
record: string,
90107
): ApprovalSubjectParams {
91108
return {
92-
object: { key: objectLabelKey(objectName), fallback: objectLabel ?? objectName },
109+
object: { object: objectName, fallback: objectLabel ?? objectName },
93110
record,
94111
};
95112
}

‎packages/plugins/plugin-approvals/src/no-approver-note.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const deliveredIn = (
4242
const params: Record<string, string> = {};
4343
for (const [name, param] of Object.entries(notice.params)) {
4444
if (typeof param === 'string') { params[name] = param; continue; }
45+
// [#35384] An object-label param is resolved off the object's metadata, which no notice here names.
46+
if ('object' in param) { params[name] = param.fallback; continue; }
4547
const looked = param.key.startsWith('messages.') ? catalog[param.key.slice('messages.'.length)] : pack[param.key];
4648
params[name] = looked ?? param.fallback;
4749
}

‎packages/plugins/plugin-approvals/src/reader-locale-labels.test.ts‎

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ describe('[#24863] the pick', () => {
110110

111111
it('negotiates through `resolveBundleLocale` even for a service that resolves exactly', () => {
112112
// A service that answers only the exact tag it holds, as `FileI18nAdapter` does.
113-
// [#35384] Asked of the step's label, the one label still read through `t()`.
113+
// [#35384] Asked of the step's label, now read off the service's translations.
114+
const packs: Record<string, Record<string, unknown>> = { en: {}, 'zh-CN': packOf({ [approvalStepLabelKey('f', 'n')]: '步骤' }) };
114115
const exact: ReaderLabelI18n = {
115-
t: (key, locale) => (locale === 'zh-CN' && key === approvalStepLabelKey('f', 'n') ? '步骤' : key),
116+
t: (key) => key,
116117
getLocales: () => ['en', 'zh-CN'],
118+
getTranslations: (locale) => packs[locale] ?? {},
117119
};
118120
expect(readerLabelsFor(exact, 'zh')!.stepLabel('f', 'n')).toBe('步骤');
119121
});
@@ -144,13 +146,19 @@ describe('[#24863] the pick', () => {
144146
expect(readerLabelsFor(undefined, 'zh-CN')).toBeUndefined();
145147
});
146148

147-
it('asks the service once per key per read', () => {
149+
it('asks the service once per read, and never through t()', () => {
148150
const asked: string[] = [];
149-
const counting: ReaderLabelI18n = { t: (key) => { asked.push(key); return key; } };
151+
let reads = 0;
152+
const counting: ReaderLabelI18n = {
153+
t: (key) => { asked.push(key); return key; },
154+
getLocales: () => ['zh-CN'],
155+
getTranslations: () => { reads += 1; return packOf(ZH); },
156+
};
150157
const labels = readerLabelsFor(counting, 'zh-CN')!;
151-
labels.stepLabel('f', 'n');
152-
labels.stepLabel('f', 'n');
153-
expect(asked).toEqual([approvalStepLabelKey('f', 'n')]);
158+
expect(labels.stepLabel('account_approval', 'manager_review')).toBe('经理审核');
159+
labels.stepLabel('account_approval', 'manager_review');
160+
expect(reads).toBe(1);
161+
expect(asked).toEqual([]);
154162
});
155163
});
156164

@@ -285,11 +293,13 @@ describe('[#35384] the object label in the declared sourceLocale reads as author
285293
});
286294

287295
/**
288-
* [#35384] The flow's and the position's labels are metadata too, so they are
289-
* resolved by the spec translators of their types — `translateFlow` (the
290-
* flow runner's reading of `flows.<flow>.label`; `/meta` serves a flow
291-
* document untranslated) and `translatePosition` (what `GET /meta/position`
292-
* serves) — with `/meta`'s `ResolveOptions`, and never through `t()`.
296+
* [#35384] The flow's, the approval step's and the position's labels are
297+
* metadata too, so they are resolved by the spec readers of their keys —
298+
* `translateFlow` (the flow runner's reading of `flows.<flow>.label`; `/meta`
299+
* serves a flow document untranslated), `resolveFlowApprovalStepLabel` (the
300+
* one reading of `flows.<flow>.approvals.<node_id>.label`) and
301+
* `translatePosition` (what `GET /meta/position` serves) — with `/meta`'s
302+
* `ResolveOptions`, and never through `t()`.
293303
*
294304
* The scenario: an app authored in English (`sourceLocale: 'en'`) that
295305
* 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
301311
* read by an `en` reader, and with no `sourceLocale` declared an `en` reader
302312
* walks the declared fallback to the `zh-CN` rows.
303313
*/
304-
describe('[#35384] the flow and position labels in the declared sourceLocale read as authored', () => {
314+
describe('[#35384] the flow, approval step and position labels in the declared sourceLocale read as authored', () => {
305315
const EN = { [flowLabelKey('other_flow')]: 'Other flow' };
306316
const declared = (sourceLocale: string | undefined, en: Record<string, string> = EN) => {
307317
const i18n = i18nWith({ 'zh-CN': ZH, en });
@@ -320,6 +330,7 @@ describe('[#35384] the flow and position labels in the declared sourceLocale rea
320330
it('the defect\'s precondition: t() answers an en reader with the zh-CN rows', () => {
321331
const i18n = declared('en');
322332
expect(i18n.t(flowLabelKey('account_approval'), 'en')).toBe('客户审批');
333+
expect(i18n.t(approvalStepLabelKey('account_approval', 'manager_review'), 'en')).toBe('经理审核');
323334
expect(i18n.t(positionLabelKey('crm_sales_manager'), 'en')).toBe('销售经理');
324335
});
325336

@@ -328,41 +339,55 @@ describe('[#35384] the flow and position labels in the declared sourceLocale rea
328339
});
329340

330341
for (const locale of ['en', 'en-US']) {
331-
it(`an ${locale} reader picks no defaultLocale row: the flow and position labels stand as authored`, () => {
342+
it(`an ${locale} reader picks no defaultLocale row: the flow, step and position labels stand as authored`, () => {
332343
const labels = readerLabelsFor(declared('en'), locale)!;
333344
expect(labels.flowLabel('account_approval')).toBeUndefined();
345+
expect(labels.stepLabel('account_approval', 'manager_review')).toBeUndefined();
334346
expect(labels.positionLabel('crm_sales_manager')).toBeUndefined();
335347
const row = served();
336348
localizeRequestLabels(row, labels);
337349
expect(row.process_label).toBe('Account Approval');
350+
expect(row.step_label).toBe('Manager Review');
351+
expect(row.current_step_label).toBe('Manager Review');
338352
});
339353
}
340354

341355
it('CONTROL: a zh-CN reader still reads the zh-CN rows', () => {
342356
const labels = readerLabelsFor(declared('en'), 'zh-CN')!;
343357
expect(labels.flowLabel('account_approval')).toBe('客户审批');
358+
expect(labels.stepLabel('account_approval', 'manager_review')).toBe('经理审核');
344359
expect(labels.positionLabel('crm_sales_manager')).toBe('销售经理');
345360
});
346361

347362
it('CONTROL: an en pack entry is what an en and an en-US reader read', () => {
348-
const en = { [flowLabelKey('account_approval')]: 'Account sign-off', [positionLabelKey('crm_sales_manager')]: 'Sales lead' };
363+
const en = {
364+
[flowLabelKey('account_approval')]: 'Account sign-off',
365+
[approvalStepLabelKey('account_approval', 'manager_review')]: 'Manager sign-off',
366+
[positionLabelKey('crm_sales_manager')]: 'Sales lead',
367+
};
349368
for (const locale of ['en', 'en-US']) {
350369
const labels = readerLabelsFor(declared('en', en), locale)!;
351370
expect(labels.flowLabel('account_approval')).toBe('Account sign-off');
371+
expect(labels.stepLabel('account_approval', 'manager_review')).toBe('Manager sign-off');
352372
expect(labels.positionLabel('crm_sales_manager')).toBe('Sales lead');
353373
}
354374
});
355375

356376
it('CONTROL: with no sourceLocale declared, an en reader walks the declared fallback to the zh-CN rows', () => {
357377
const labels = readerLabelsFor(declared(undefined), 'en')!;
358378
expect(labels.flowLabel('account_approval')).toBe('客户审批');
379+
expect(labels.stepLabel('account_approval', 'manager_review')).toBe('经理审核');
359380
expect(labels.positionLabel('crm_sales_manager')).toBe('销售经理');
360381
});
361382

362-
it('reads neither label through t(): a service that cannot hand its translations over picks none', () => {
363-
const tOnly: ReaderLabelI18n = { t: (key) => (key === flowLabelKey('f') ? '流程' : key === positionLabelKey('p') ? '岗位' : key) };
383+
it('reads no label through t(): a service that cannot hand its translations over picks none', () => {
384+
const tOnly: ReaderLabelI18n = {
385+
t: (key) => (key === flowLabelKey('f') ? '流程' : key === positionLabelKey('p') ? '岗位'
386+
: key === approvalStepLabelKey('f', 'n') ? '步骤' : key),
387+
};
364388
const labels = readerLabelsFor(tOnly, 'zh-CN')!;
365389
expect(labels.flowLabel('f')).toBeUndefined();
390+
expect(labels.stepLabel('f', 'n')).toBeUndefined();
366391
expect(labels.positionLabel('p')).toBeUndefined();
367392
});
368393

0 commit comments

Comments
 (0)