Skip to content

Commit 06b0d43

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

6 files changed

Lines changed: 349 additions & 33 deletions

File tree

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,33 @@
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, `{ objectLabel: <object>, 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+
readonly objectLabel: string;
59+
readonly fallback: string;
60+
}
4561

4662
/**
4763
* The keyed half — the structural mirror of the messaging service's
@@ -68,7 +84,7 @@ export interface ApprovalNotificationText {
6884
* not an interface, so it spreads into a sentence's params as it stands.
6985
*/
7086
export type ApprovalSubjectParams = {
71-
readonly object: { readonly key: string; readonly fallback: string };
87+
readonly object: ApprovalObjectLabelParam;
7288
readonly record: string;
7389
};
7490

@@ -78,9 +94,9 @@ export function approvalMessageKey(id: ApprovalMessageId): string {
7894
}
7995

8096
/**
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
97+
* The record of `objectName` a notification names: the object's label — the
98+
* typed object-label param naming `objectName`, falling back to `objectLabel`
99+
* (the schema label), else the API name — and `record`, the name its recipient reads for
84100
* it (its title as they may read it, else its id).
85101
*/
86102
export function subjectParams(
@@ -89,7 +105,7 @@ export function subjectParams(
89105
record: string,
90106
): ApprovalSubjectParams {
91107
return {
92-
object: { key: objectLabelKey(objectName), fallback: objectLabel ?? objectName },
108+
object: { objectLabel: objectName, fallback: objectLabel ?? objectName },
93109
record,
94110
};
95111
}

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
* - the text is `II18nService.t(key, locale)`; a miss is the key echoed back,
3030
* and then the authored text stands.
3131
*
32-
* [#35384] Except a METADATA label: the object's, the flow's and the
33-
* position's. Each is resolved by the spec translator of its type
32+
* [#35384] Except a METADATA label: the object's, the flow's, the approval
33+
* step's and the position's. Each is resolved by the spec translator of its type
3434
* (`@objectstack/spec/system`) over every locale the service holds, with the
3535
* metadata route's `ResolveOptions` ({@link metaLabelTranslation}: the
3636
* reader's locale, the DECLARED fallback chain, and the authored language,
@@ -44,13 +44,14 @@
4444
* - the flow's by `translateFlow`, the translator the flow runner names a
4545
* flow by. `/meta` serves a flow document untranslated (`translateFlow` is
4646
* deliberately not in `translateMetadataDocument`'s table), so this is the
47-
* spec's one reading of `flows.<flow>.label`.
47+
* spec's one reading of `flows.<flow>.label`;
48+
* - the approval step's by `resolveFlowApprovalStepLabel`, the spec's one
49+
* reading of `flows.<flow>.approvals.<node_id>.label`, over the flow's name
50+
* and the node's id the stored row carries (no flow document is read).
4851
*
4952
* So a reader in a deployment's declared `sourceLocale` reads these labels as
5053
* authored, never the `defaultLocale` row `t()` falls back to. `t()` carries
51-
* the catalog sentences, and still the approval STEP's label: no spec
52-
* translator reads `flows.<flow>.approvals.<node_id>.label` yet, and a second
53-
* walk of the locale chain here would be a second resolver.
54+
* the catalog sentences only.
5455
*
5556
* objectql names a refused write's object this way (`objectDisplayLabel`,
5657
* through `objectLabelKey`), the REST door names a NOT NULL field this way
@@ -70,9 +71,10 @@
7071
* own `label` (`translation.zod.ts`, `positions`), which `translatePosition`
7172
* overlays on every served `position` document.
7273
*
73-
* [#35384] Only the step's key is asked of `t()`. The flow and position keys
74-
* are still spelled here, for the contract pin and for the readers that name
75-
* them; `translateFlow` and `translatePosition` read the same addresses.
74+
* [#35384] No key is asked of `t()`. The flow, step and position keys are
75+
* still spelled here, for the contract pin and for the readers that name
76+
* them; `translateFlow`, `resolveFlowApprovalStepLabel` and
77+
* `translatePosition` read the same addresses.
7678
*
7779
* `<flow>` is the request's `process_name` without its `flow:` prefix, the
7880
* `Flow.name` the engine hands the node (`$flowName`), and `<node_id>` is its
@@ -100,6 +102,7 @@
100102
import type { II18nService } from '@objectstack/spec/contracts';
101103
import {
102104
resolveBundleLocale,
105+
resolveFlowApprovalStepLabel,
103106
translateFlow,
104107
translateObject,
105108
translatePosition,
@@ -338,8 +341,6 @@ export function readerLabelsFor(
338341
seen.set(key, value);
339342
return value;
340343
};
341-
const picked = new Map<string, string | undefined>();
342-
const pick = (key: string): string | undefined => memo(picked, key, () => render(key));
343344
// [#35384] Built on the first metadata label this read asks, once.
344345
let translation: { value: MetaLabelTranslation | undefined } | undefined;
345346
/** One metadata label through its spec translator; `undefined` on any miss or throw. */
@@ -359,6 +360,12 @@ export function readerLabelsFor(
359360
const doc: FlowLike = { name: flowName };
360361
return translateFlow(doc, bundle, options).label;
361362
}));
363+
// [#35384] The step's label, as the spec reads `flows.<flow>.approvals.<node_id>.label`;
364+
// no literal, so a miss picks nothing and the stored snapshot stands.
365+
const stepLabels = new Map<string, string | undefined>();
366+
const stepLabel = (flowName: string, nodeId: string): string | undefined =>
367+
memo(stepLabels, approvalStepLabelKey(flowName, nodeId), () =>
368+
translated(({ bundle, options }) => resolveFlowApprovalStepLabel(bundle, flowName, nodeId, undefined, options)));
362369
const positionLabels = new Map<string, string | undefined>();
363370
const positionLabel = (positionName: string): string | undefined =>
364371
memo(positionLabels, positionName, () =>
@@ -377,7 +384,7 @@ export function readerLabelsFor(
377384
}));
378385
return {
379386
flowLabel,
380-
stepLabel: (flowName, nodeId) => pick(approvalStepLabelKey(flowName, nodeId)),
387+
stepLabel,
381388
objectLabel,
382389
positionLabel,
383390
sentence: (key, params) => render(key, params),

‎packages/services/service-messaging/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export {
114114
export type {
115115
NotificationTextKeys,
116116
NotificationTextParam,
117+
NotificationObjectLabelParam,
117118
NotificationTextI18n,
118119
NotificationTextItem,
119120
NotificationTextRendererOptions,

0 commit comments

Comments
 (0)