Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/35979-flow-node-label-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@objectstack/spec': minor
'@objectstack/lint': minor
'@objectstack/cli': minor
'@object-ui/i18n': minor
'@object-ui/components': patch
---

feat(spec): every step a flow drawing shows can be translated, under `flows.<flow>.nodes.<node_id>.label`

Clause-②: yes (widening: a new translation key `flows.<flow>.nodes.<node_id>.label`; the new exports `FLOW_TECHNICAL_NODE_TYPES` and `isFlowTechnicalNodeType` from `@objectstack/spec/automation`; and `@object-ui/i18n`'s exported `FlowLabelTranslations` type gains the member `screenTitle`, and its `stepLabel` parameter accepts a `config`)
Metadata-protocol: added
Skills-docs: follow-up #36401

A package can now translate the label of any flow step, not only a screen's heading and an approval step's label. A manual that embeds a flow (a `type: flow` metadata embed) lists its steps by label, and until now a start, decision, notify or end step had nowhere to put a translation, so a zh-CN reader saw those steps in English beside translated approval steps.

- **The key.** `flows.<flow>.nodes.<node_id>.label`, keyed by the node's `id`, at any depth. It overlays the node's own `label` and is plain text. A `screen` keeps its `screens.<node_id>.title` and an `approval` its `approvals.<node_id>.label`, so one string keeps one key: `objectstack validate` points a `nodes` key over either at that key, and points a `screens` or `approvals` key over any other node at `nodes.<node_id>.label`. A key over a node the flow does not declare is refused. `nodes` was an unknown-key hint that suggested `screens`; it is now its own group.
- **Start and end steps are translated like any other.** Their labels are the author's words and often name an outcome or a trigger ("Approved", "On Task Created"), so nothing substitutes words of its own for them.
- **Missing translations are reported.** `os lint` and `os i18n check` (`i18n/missing-flow`) now ask for the label of every top-level step the embed draws at its default `detail: business` altitude, except screens and approvals, which they already asked for, and of a folded technical step where a drawn decision's branch list names it as the step the branch leads to (a decision whose branch runs a `script` first). `os i18n extract` scaffolds the keys. An app that ships translated locales gets new findings for its flows until it translates them.
- **The drawings read it.** The docs viewer's `type: flow` embed (`element:metadata_viewer`) and the Studio flow designer's canvas, nested region nodes included, now name each step by its translation in the reader's language, through the one resolution in `@object-ui/i18n`: `stepLabel` reads `approvals.<node_id>.label` for an approval, `screens.<node_id>.title` for a screen with no `config.title`, and `nodes.<node_id>.label` for any other node. A step the package leaves untranslated keeps its authored label. A decision's branch list names the step a branch leads to the same way.
- **A titled screen is named by its heading in the docs embed.** A screen that authors its own `config.title` shows that heading at run time, translated under `screens.<node_id>.title`, so the embed names it by the heading (translated where the bundle carries it) instead of its canvas label, which has no key. A heading with a `{{ }}` hole cannot be filled in a drawing, so such a screen keeps its authored label. `FlowLabelTranslations` gains `screenTitle` for this read. The Studio canvas keeps a titled screen's authored label.
- **One table for what business altitude hides.** `FLOW_TECHNICAL_NODE_TYPES` (and `isFlowTechnicalNodeType`) in `@objectstack/spec/automation` lists the node types `detail: business` folds away (`script`, `http`, `connector_action`, `assignment`, `get_record`, `create_record`, `update_record`, `delete_record`, `boundary_event`). The docs viewer folds steps by it and the coverage check asks for translations by it, so they agree on which steps a reader sees.
1 change: 1 addition & 0 deletions content/docs/protocol/kernel/i18n-standard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ beneath an action entry are judged the same way under either.
| `hooks.{hook}.refusals.{code}.reasons.{reason}` | a reason that code declares under `reasons` |
| `flows.{flow}.screens.{node}` | the `id` of a `type: 'screen'` node in that flow, nodes nested in loop, parallel and try/catch regions included |
| `flows.{flow}.screens.{node}.fields.{field}` | a `config.fields[].name` on that screen — an object-form screen (`config.objectName`) declares none, and its input labels live under `objects.{objectName}.fields` |
| `flows.{flow}.nodes.{node}` | the `id` of a node in that flow that is neither a `screen` nor an `approval` (those two are keyed under `screens` and `approvals`), nodes nested in loop, parallel and try/catch regions included |

An unresolvable key is an **error**, not a warning: `os validate`, `os lint` and
`os compile` each report it as `translation-target-unknown` and exit non-zero, so
Expand Down
4 changes: 4 additions & 0 deletions content/docs/references/system/translation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ Translation data for a single object
| **screens** | `Record<string, { title?: string; description?: string; fields?: Record<string, object> }>` | optional | Screen translations keyed by screen node id (`FlowNode.id`, the client's `ScreenSpec.nodeId`) |
| **refusals** | `Record<string, { message?: string }>` | optional | Refusal translations keyed by the node id (`FlowNode.id`) of an `end` node declaring `outcome: 'refused'` |
| **approvals** | `Record<string, { label?: string }>` | optional | Approval-step translations keyed by the node id (`FlowNode.id`) of an `approval` node |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than a `screen` or an `approval` |
| **notices** | `Record<string, { message?: string }>` | optional | Save-notice translations keyed by the node id (`FlowNode.id`) of a `save_notice` node |
| **records** | `Record<string, { fields?: Record<string, string> }>` | optional | Record-write text translations keyed by the node id (`FlowNode.id`) of a `create_record` / `update_record` node |

Expand Down Expand Up @@ -486,6 +487,7 @@ Translation data for a single object
| **screens** | `Record<string, { title?: string; description?: string; fields?: Record<string, object> }>` | optional | Screen translations keyed by screen node id (`FlowNode.id`, the client's `ScreenSpec.nodeId`) |
| **refusals** | `Record<string, { message?: string }>` | optional | Refusal translations keyed by the node id (`FlowNode.id`) of an `end` node declaring `outcome: 'refused'` |
| **approvals** | `Record<string, { label?: string }>` | optional | Approval-step translations keyed by the node id (`FlowNode.id`) of an `approval` node |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than a `screen` or an `approval` |
| **notices** | `Record<string, { message?: string }>` | optional | Save-notice translations keyed by the node id (`FlowNode.id`) of a `save_notice` node |
| **records** | `Record<string, { fields?: Record<string, string> }>` | optional | Record-write text translations keyed by the node id (`FlowNode.id`) of a `create_record` / `update_record` node |

Expand Down Expand Up @@ -738,6 +740,7 @@ Translation data for a single object
| **screens** | `Record<string, { title?: string; description?: string; fields?: Record<string, object> }>` | optional | Screen translations keyed by screen node id (`FlowNode.id`, the client's `ScreenSpec.nodeId`) |
| **refusals** | `Record<string, { message?: string }>` | optional | Refusal translations keyed by the node id (`FlowNode.id`) of an `end` node declaring `outcome: 'refused'` |
| **approvals** | `Record<string, { label?: string }>` | optional | Approval-step translations keyed by the node id (`FlowNode.id`) of an `approval` node |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than a `screen` or an `approval` |
| **notices** | `Record<string, { message?: string }>` | optional | Save-notice translations keyed by the node id (`FlowNode.id`) of a `save_notice` node |
| **records** | `Record<string, { fields?: Record<string, string> }>` | optional | Record-write text translations keyed by the node id (`FlowNode.id`) of a `create_record` / `update_record` node |

Expand Down Expand Up @@ -959,6 +962,7 @@ Translation data for a single object
| **screens** | `Record<string, { title?: string; description?: string; fields?: Record<string, object> }>` | optional | Screen translations keyed by screen node id (`FlowNode.id`, the client's `ScreenSpec.nodeId`) |
| **refusals** | `Record<string, { message?: string }>` | optional | Refusal translations keyed by the node id (`FlowNode.id`) of an `end` node declaring `outcome: 'refused'` |
| **approvals** | `Record<string, { label?: string }>` | optional | Approval-step translations keyed by the node id (`FlowNode.id`) of an `approval` node |
| **nodes** | `Record<string, { label?: string }>` | optional | Node-label translations keyed by node id (`FlowNode.id`) — every node other than a `screen` or an `approval` |
| **notices** | `Record<string, { message?: string }>` | optional | Save-notice translations keyed by the node id (`FlowNode.id`) of a `save_notice` node |
| **records** | `Record<string, { fields?: Record<string, string> }>` | optional | Record-write text translations keyed by the node id (`FlowNode.id`) of a `create_record` / `update_record` node |

Expand Down
1 change: 1 addition & 0 deletions content/docs/ui/translations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default defineStack({
| Page tab labels (`page:tabs` items) | `pages.<name>.components.<tabsId>.items.<value>.label` — keyed by the tabs component's `id` and the item's `value`; an item without a `value` has no key (localize it with an inline locale map), and `page:accordion` panels have none |
| A page `object-form`'s thank-you panel | `pages.<name>.components.<formId>.submitBehavior.title` / `.message` — keyed by the `object-form` component's `id` (a form without an `id` has no key), by the same rules as a form view's panel |
| Screen-flow wizards (flow label, screen headings and body text, screen field copy) | `flows.<flow>.label` / `flows.<flow>.screens.<node_id>.title` / `.description` / `.fields.<field>.label` / `.placeholder` / `.inlineHelpText` — a screen field's help text is `inlineHelpText`, the key the field itself declares, not `help`; see the boundary note below |
| Flow step names (each step a drawing of the flow shows, such as a manual's flow embed) | `flows.<flow>.nodes.<node_id>.label` — keyed by the node's `id`, for a start, decision, notify, end or any other step; an `approval` step's name is `flows.<flow>.approvals.<node_id>.label` and a screen's is its heading, `flows.<flow>.screens.<node_id>.title`, so `os validate` points a `nodes` key over either there. `os lint` asks for every step a flow embed draws at its default business altitude |
| Text a flow writes into a record (a `create_record` / `update_record` field value marked `{ dialect: 'template', source }`) | `flows.<flow>.records.<node_id>.fields.<field>` — picked in the organization's language (the Localization setting when set, else the app's `i18n.defaultLocale`), never the run starter's; see [Flows](/docs/automation/flows#text-a-record-keeps--a-field-value-marked-as-text) |
| Hook refusal messages | `hooks.<hook>.refusals.<CODE>.message` — one per entry of the hook's `refusals` catalogue — and `hooks.<hook>.refusals.<CODE>.reasons.<REASON>.message`, one per reason an entry declares. A hook (a `js` body or a TypeScript `handler`) refuses by code, optionally with a declared reason, and the server answers the refusal with this sentence in the caller's locale, else the declared one. A translation of an entry that declares `params` keeps its `{{ name }}` holes; the server fills them after picking the translation |
| Hook texts | `hooks.<hook>.texts.<key>.message` — one per entry of the hook's `texts`. A hook asks for the sentence with `ctx.text(key, params)` when it writes it into a record, and the server answers it in the **organization's** language (the Localization setting somebody set, else the app's `i18n.defaultLocale`), never the caller's, else the declared one. A translation of an entry that declares `params` keeps its `{{ name }}` holes; the server fills them after picking the translation |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate.

| Dir | Sites |
|---|---|
| `system/` | 407 |
| `system/` | 408 |
6 changes: 6 additions & 0 deletions examples/app-crm/src/translations/crm.translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ export const CrmTranslationBundle = defineTranslationBundle({
label: '将线索转化为客户和商机',
successMessage: '🎉 线索已转化 — 已创建客户和商机。',
errorMessage: '线索转化未完成 — 请检查线索后重试。',
// Each step's name where a manual draws the flow.
nodes: {
start: { label: '开始' },
check_converted: { label: '已转化?' },
end: { label: '结束' },
},
screens: {
screen_already_converted: { title: '已转化', description: '该线索已转化为商机。' },
screen_account: {
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/utils/i18n-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ const COVERAGE_SOURCE: Record<ExpectedEntry['source'], CoverageIssue['source']>
// toasts (`flows.<f>.successMessage` / `.errorMessage`, #22507) and a refused
// `end` node's message (`flows.<f>.refusals.<n>.message`, #22450), and an
// approval flow's label with each `approval` node's step label
// (`flows.<f>.approvals.<n>.label`, #24916) — the author's own text, so
// (`flows.<f>.approvals.<n>.label`, #24916), and every other step a docs
// flow embed draws (`flows.<f>.nodes.<n>.label`, ruling 7076440876) — the
// author's own text, so
// it keeps its own bucket and reports as `i18n/missing-flow` rather than
// folding away with `--include-platform`. Until this bucket existed the
// family could not report a screen-flow gap at all: HotCRM measured
Expand Down Expand Up @@ -461,7 +463,7 @@ const SOURCE_SURFACE: Record<CoverageIssue['source'], string> = {
report: 'reports',
picklist: 'picklists',
page: 'pages',
flow: 'flow screens, approval steps, toasts and refusals',
flow: 'flow screens, steps, approval steps, toasts and refusals',
hook: 'hook refusals',
position: 'positions',
permission: 'permission sets',
Expand Down
19 changes: 14 additions & 5 deletions packages/cli/test/i18n-flow-approval-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ import { collectExpectedEntries, extractTranslations } from '../src/utils/i18n-b
import { computeI18nCoverage } from '../src/utils/i18n-coverage.js';
import { TranslationDataSchema } from '@objectstack/spec/system';

/**
* The `flows.<flow>.nodes.<node_id>.label` family (ruling 7076440876) is
* demanded beside this file's own and pinned by `i18n-flow-node-coverage.test.ts`;
* these pins measure their family, so they read every key but that one.
*/
const notNodeLabel = (key: string) => !/^flows\.[^.]+\.nodes\./.test(key);

/** An approval-only flow: record-triggered, two approval steps, no screen. */
const expenseApproval = {
name: 'expense_approval',
Expand Down Expand Up @@ -67,11 +74,13 @@ const nightlyDigest = {
};

const flowKeys = (config: any) =>
collectExpectedEntries(config).filter((e) => e.path[0] === 'flows').map((e) => e.path.join('.'));
collectExpectedEntries(config).filter((e) => e.path[0] === 'flows').map((e) => e.path.join('.')).filter(notNodeLabel);

describe('what the walker harvests from an approval flow (#24916)', () => {
it('emits the flow label and each approval step label, seeded with the authored text', () => {
const entries = collectExpectedEntries({ flows: [expenseApproval] }).filter((e) => e.path[0] === 'flows');
const entries = collectExpectedEntries({ flows: [expenseApproval] }).filter(
(e) => e.path[0] === 'flows' && notNodeLabel(e.path.join('.')),
);

expect(entries.map((e) => e.path.join('.'))).toEqual([
'flows.expense_approval.label',
Expand Down Expand Up @@ -99,7 +108,7 @@ describe('the coverage gate demands the approval flow and its steps (#24916)', (
translations: [{ 'zh-CN': { ...(flows ? { flows } : {}) } }],
});
const zhFlowIssues = (config: any) =>
computeI18nCoverage(config).issues.filter((i) => i.locale === 'zh-CN' && i.source === 'flow');
computeI18nCoverage(config).issues.filter((i) => i.locale === 'zh-CN' && i.source === 'flow' && notNodeLabel(i.key));

it('lists the untranslated approval flow label and step labels in the flow bucket', () => {
const keys = zhFlowIssues(tree()).map((i) => i.key).filter((k) => k.startsWith('flows.expense_approval.'));
Expand Down Expand Up @@ -154,11 +163,11 @@ describe('the skeleton `os i18n extract` writes for an approval flow (#24916)',
const result = extractTranslations({ flows: [expenseApproval] }, { locales: ['en', 'zh-CN'] });

it('writes the authored labels into the default locale and empty slots into the others', () => {
expect((result.bundles.en as any).flows.expense_approval).toEqual({
expect((result.bundles.en as any).flows.expense_approval).toMatchObject({
label: 'Expense Approval',
approvals: { manager_review: { label: 'Manager Review' }, finance_review: { label: 'Finance Review' } },
});
expect((result.bundles['zh-CN'] as any).flows.expense_approval).toEqual({
expect((result.bundles['zh-CN'] as any).flows.expense_approval).toMatchObject({
label: '',
approvals: { manager_review: { label: '' }, finance_review: { label: '' } },
});
Expand Down
10 changes: 9 additions & 1 deletion packages/cli/test/i18n-flow-liveness-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ import {
import { computeI18nCoverage } from '../src/utils/i18n-coverage.js';
import { authorWarnedProperties, lintLivenessProperties } from '@objectstack/lint';

/**
* The `flows.<flow>.nodes.<node_id>.label` family (ruling 7076440876) is
* demanded beside this file's own and pinned by `i18n-flow-node-coverage.test.ts`;
* these pins measure their family, so they read every key but that one.
*/
const notNodeLabel = (key: string) => !/^flows\.[^.]+\.nodes\./.test(key);

const leadConversion = {
name: 'lead_conversion',
label: 'Convert Lead',
Expand Down Expand Up @@ -114,7 +121,7 @@ const app = (withFlowCopy: boolean) => ({
});

const flowDemands = (config: any) =>
computeI18nCoverage(config).issues.filter((i) => i.source === 'flow');
computeI18nCoverage(config).issues.filter((i) => i.source === 'flow' && notNodeLabel(i.key));
const flowWarnings = (config: any) =>
lintLivenessProperties(config).filter((f) => f.message.includes('`flows`'));

Expand Down Expand Up @@ -210,6 +217,7 @@ describe('the liveness gate on the i18n coverage walk', () => {
const keys = collectExpectedEntries(app(false), UNGATED)
.filter((e) => e.path[0] === 'flows')
.map((e) => e.path.join('.'))
.filter(notNodeLabel)
.sort();

expect(keys).toEqual([
Expand Down
Loading
Loading