Skip to content

Commit e727a36

Browse files
committed
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 <noreply@anthropic.com>
1 parent 06b0d43 commit e727a36

5 files changed

Lines changed: 299 additions & 20 deletions

File tree

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, `{ objectLabel: '<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.
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 (`{ objectLabel, 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/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)