From 68142ba6f4b3bbb98b192b7a0abb8fcc63c28fd6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 03:43:41 +0000 Subject: [PATCH 1/7] fix(components): the docs viewer's flow embed names the flow and its approval steps in the reader's language The flow-label resolution the Studio designer and FlowRunner read moves from app-shell into @object-ui/i18n, so the docs viewer's FlowView reads the same flows.FLOW.label and flows.FLOW.approvals.STEP.label, falling back to the authored text. Claude-Session: https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1 Co-Authored-By: Claude --- .../app-shell/src/utils/flowsBundle.ts | 67 ---------- .../app-shell/src/views/FlowRunner.tsx | 4 +- .../previews/FlowCanvas.test.tsx | 4 +- .../previews/flow-label-translations.tsx | 65 +++------- .../src/renderers/basic/metadata-viewer.tsx | 13 +- ui/packages/i18n/src/flowLabels.ts | 119 ++++++++++++++++++ ui/packages/i18n/src/index.ts | 12 ++ 7 files changed, 158 insertions(+), 126 deletions(-) delete mode 100644 ui/packages/app-shell/src/utils/flowsBundle.ts create mode 100644 ui/packages/i18n/src/flowLabels.ts diff --git a/ui/packages/app-shell/src/utils/flowsBundle.ts b/ui/packages/app-shell/src/utils/flowsBundle.ts deleted file mode 100644 index 9961cd10307..00000000000 --- a/ui/packages/app-shell/src/utils/flowsBundle.ts +++ /dev/null @@ -1,67 +0,0 @@ -/** - * ObjectUI - * Copyright (c) 2024-present ObjectStack Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/** - * The app's `flows` translation group, read back out of the i18next resource - * tree the console already loaded — the ONE reader of that group in the - * console. Module-internal (not re-exported from `utils/index` or the package - * entry). - * - * Three surfaces read it, all for the flow a run belongs to: `FlowRunner` - * (the paused screen's field copy and option labels, the flow's label, the - * resume's terminal toasts) and the two flow-LAUNCH hosts through - * `launchConsoleFlow` (a straight-through run's terminal toasts, - * objectui#12075). They read it through this module so the three cannot - * disagree about where the bundle lives. - * - * The provider's `loadLanguage` hands the app's translation payload to - * i18next (`transformSpecTranslations` forwards `flows` verbatim under the app - * namespace), so there is no second loader. - */ - -import type { TranslationBundle, TranslationData } from '@objectstack/spec/system'; - -/** The `flows` group of a spec `TranslationData` — typed by the spec, so the address below is checked against it. */ -export type FlowsTranslation = NonNullable; - -/** - * The one member of the i18next instance the bundle read needs. Optional, - * because outside a provider react-i18next hands back a placeholder object - * that has none — and then there is no bundle, only the authored copy. - */ -export interface TranslationResourceReader { - getResourceBundle?: (lng: string, ns: string) => unknown; -} - -/** - * The active language's `flows` group as a spec `TranslationBundle`, or - * `undefined` when the resource tree translates nothing for `flowName`. - * - * App translations sit under an app namespace at the top of that tree (`app` - * for a spec payload, whatever the payload named for an already-namespaced - * one), so the first namespace whose `flows` group addresses this flow is the - * one read. The bundle is keyed by `language` itself, and the resolvers are - * asked for `language` with no fallback chain: a string the active language - * does not carry falls back to the author's copy, never to a third locale. - */ -export function activeFlowsBundle( - i18n: TranslationResourceReader | undefined, - language: string, - flowName: string, -): TranslationBundle | undefined { - if (!flowName || typeof i18n?.getResourceBundle !== 'function') return undefined; - const tree = i18n.getResourceBundle(language, 'translation'); - if (!tree || typeof tree !== 'object') return undefined; - for (const namespace of Object.values(tree as Record)) { - const flows = (namespace as { flows?: unknown } | null)?.flows; - if (flows && typeof flows === 'object' && (flows as Record)[flowName]) { - return { [language]: { flows: flows as FlowsTranslation } }; - } - } - return undefined; -} diff --git a/ui/packages/app-shell/src/views/FlowRunner.tsx b/ui/packages/app-shell/src/views/FlowRunner.tsx index c22bcf22da4..5d844bb5346 100644 --- a/ui/packages/app-shell/src/views/FlowRunner.tsx +++ b/ui/packages/app-shell/src/views/FlowRunner.tsx @@ -158,7 +158,7 @@ * launch hosts alike. * * WHERE the bundle comes from is the channel the console already has: - * `activeFlowsBundle` (`utils/flowsBundle`) reads the `flows` group back out + * `activeFlowsBundle` (`@object-ui/i18n`) reads the `flows` group back out * of the i18next resource tree the provider loaded, for the active language. * There is no second loader. * @@ -349,7 +349,7 @@ import { } from './ScreenView.js'; import { flowSuccessCopy, interpretFlowResponse } from '../utils/flowResponse.js'; import { announceFlowDroppedFields } from '../utils/flowLaunch.js'; -import { activeFlowsBundle, type FlowsTranslation } from '../utils/flowsBundle.js'; +import { activeFlowsBundle, type FlowsTranslation } from '@object-ui/i18n'; export type { ScreenSpec, ScreenFieldSpec } from './ScreenView.js'; diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx index 9bfdf5792a1..98bc62515df 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx @@ -10,16 +10,14 @@ import type { FlowProblem } from './flow-problems'; import { browserClick, browserDrag } from './__tests__/browserClick'; // FlowPreview reaches a dynamic `import('@objectstack/lint')`; pay its load at collection, not in a test's clock. import '@objectstack/lint'; -import { createI18n, I18nProvider, transformSpecTranslations } from '@object-ui/i18n'; +import { activeFlowsBundle, createI18n, flowLabelTranslations, I18nProvider, transformSpecTranslations } from '@object-ui/i18n'; import type { TranslationData } from '@objectstack/spec/system'; import { FlowPreview, FlowSelectionTitle, flowSelectionHeading } from './FlowPreview'; import { FlowLabelTranslationsProvider, - flowLabelTranslations, useFlowLabelTranslations, type FlowLabelTranslations, } from './flow-label-translations'; -import { activeFlowsBundle } from '../../../utils/flowsBundle'; afterEach(cleanup); diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx index ea76d0119e6..827e44695f1 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx @@ -5,15 +5,12 @@ * own label (`flows..label`) and an `approval` node's step label * (`flows..approvals..label`), in the viewer's language. * - * The bundle is the one `FlowRunner` reads, `activeFlowsBundle` over the - * i18next resource tree the console already loaded, and the flow label goes - * through the spec's `translateFlow`, the runner's resolution path. So the - * designer and the runner cannot disagree about a flow's name, and there is no - * second loader. - * - * Only those two keys exist in the spec's `flows` group for a label the - * designer draws. A decision or other node's label and an edge label have no - * key, so they stay the authored text. + * The resolution itself is `@object-ui/i18n`'s (`flowLabelTranslations` over + * `activeFlowsBundle`), the one the runner and the docs viewer's flow embed + * read too, so no two surfaces can disagree about a flow's name and there is + * no second loader. This module adds only what the designer needs on top: + * a per-row reader for the Automations rail and a context that hands the + * translations to the canvas. * * Display only: the draft is never rewritten with a translation, so an edit, * a rename or a save keeps working on the authored label. Studio is the @@ -23,48 +20,13 @@ import * as React from 'react'; import { useObjectTranslation } from '@object-ui/react'; -import { translateFlow, type TranslationBundle } from '@objectstack/spec/system'; -import { activeFlowsBundle } from '../../../utils/flowsBundle.js'; - -/** A flow's translated labels in one language. Every member answers `undefined` where the bundle carries nothing. */ -export interface FlowLabelTranslations { - /** `flows..label`. */ - flowLabel?: string; - /** `flows..approvals..label`, for an `approval` node only. */ - stepLabel: (node: { id?: unknown; type?: unknown }) => string | undefined; -} +import { + activeFlowsBundle, + flowLabelTranslations, + type FlowLabelTranslations, +} from '@object-ui/i18n'; -/** - * The translated labels for `flowName` out of `bundle` in `language`, or - * `undefined` when there is no bundle (nothing to translate with). - */ -export function flowLabelTranslations( - bundle: TranslationBundle | undefined, - flowName: string, - language: string, -): FlowLabelTranslations | undefined { - if (!bundle || !flowName) return undefined; - const flowLabel = translateFlow<{ name: string; label?: string }>({ name: flowName }, bundle, { locale: language }).label; - const approvals = bundle[language]?.flows?.[flowName]?.approvals; - return { - flowLabel: typeof flowLabel === 'string' && flowLabel ? flowLabel : undefined, - stepLabel: (node) => { - if (node.type !== 'approval' || typeof node.id !== 'string' || !node.id) return undefined; - const label = approvals?.[node.id]?.label; - return typeof label === 'string' && label ? label : undefined; - }, - }; -} - -/** - * {@link flowLabelTranslations} for `flowName` in the console's active - * language. Recomputed on every render: a handful of property reads that - * follow the live resource tree and a language switch. - */ -export function useFlowLabelTranslations(flowName: string): FlowLabelTranslations | undefined { - const { i18n, language } = useObjectTranslation(); - return flowLabelTranslations(activeFlowsBundle(i18n, language, flowName), flowName, language); -} +export { useFlowLabelTranslations, type FlowLabelTranslations } from '@object-ui/i18n'; /** * The flow label of any flow, by name, for a surface that lists many: the @@ -73,7 +35,8 @@ export function useFlowLabelTranslations(flowName: string): FlowLabelTranslation * the reading the designer header makes for the open flow, so a row and the * flow it opens cannot disagree. `undefined` where the bundle carries no label * for that flow, and the caller keeps the authored label. A fresh function on - * every render, for the reason above. + * every render: a handful of property reads that follow the live resource tree + * and a language switch. */ export function useFlowLabelOf(): (flowName: string) => string | undefined { const { i18n, language } = useObjectTranslation(); diff --git a/ui/packages/components/src/renderers/basic/metadata-viewer.tsx b/ui/packages/components/src/renderers/basic/metadata-viewer.tsx index b89f604017f..4be3f23d52b 100644 --- a/ui/packages/components/src/renderers/basic/metadata-viewer.tsx +++ b/ui/packages/components/src/renderers/basic/metadata-viewer.tsx @@ -21,7 +21,7 @@ import * as React from 'react'; import { ComponentRegistry } from '@object-ui/core'; import { useMetadataItem, resolveInlineAriaProps } from '@object-ui/react'; -import { useDisplayLocale, useObjectTranslation } from '@object-ui/i18n'; +import { useDisplayLocale, useFlowLabelTranslations, useObjectTranslation } from '@object-ui/i18n'; import type { AriaProps } from '@object-ui/types'; import { ArrowRight, @@ -384,6 +384,10 @@ const TECHNICAL_NODE_TYPES = new Set([ function FlowView({ name, detail }: ViewerProps) { const { item: flow, loading, error } = useMetadataItem('flow', name ?? null); const { t, ...view } = useViewStates(); + // The package's `flows` translations in the reader's language: the flow label + // and each `approval` step's label, the resolution the Studio designer and + // the runner share. Any other step has no key and keeps its authored label. + const translated = useFlowLabelTranslations(name ?? ''); if (!name) return view.missing('name'); if (loading) return view.loading(name); @@ -399,7 +403,7 @@ function FlowView({ name, detail }: ViewerProps) { - {n?.label ?? n?.id ?? t('element.metadataViewer.untitledStep', { defaultValue: '(step)' })} + {(n && translated?.stepLabel(n)) ?? + n?.label ?? + n?.id ?? + t('element.metadataViewer.untitledStep', { defaultValue: '(step)' })} {n?.type && ( diff --git a/ui/packages/i18n/src/flowLabels.ts b/ui/packages/i18n/src/flowLabels.ts new file mode 100644 index 00000000000..7b46c2cc80e --- /dev/null +++ b/ui/packages/i18n/src/flowLabels.ts @@ -0,0 +1,119 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * An app's `flows` translation group, read back out of the i18next resource + * tree the host already loaded, and the two flow labels a surface that DRAWS a + * flow resolves from it: the flow's own label (`flows..label`) and an + * `approval` node's step label (`flows..approvals..label`). + * + * This is the ONE reader of that group in the UI. It lives here, beside the + * provider whose resource tree it reads, so every surface reads it the same + * way: the console's `FlowRunner` and flow-launch hosts, the Studio flow + * designer, and the docs viewer's `type: flow` embed + * (`element:metadata_viewer`). None of them can disagree about where the + * bundle lives or what a flow is called. + * + * The provider's `loadLanguage` hands the app's translation payload to + * i18next (`transformSpecTranslations` forwards `flows` verbatim under the app + * namespace), so there is no second loader. + * + * Only those two keys exist in the spec's `flows` group for a label a flow + * drawing shows. A decision, notify, start or end node's label and an edge + * label have no key, so they stay the authored text. + * + * Display only: nothing here rewrites the flow, so an editor keeps working on + * the authored label. + */ + +import { translateFlow, type TranslationBundle, type TranslationData } from '@objectstack/spec/system'; +import { useObjectTranslation } from './provider.js'; + +/** The `flows` group of a spec `TranslationData` — typed by the spec, so the address below is checked against it. */ +export type FlowsTranslation = NonNullable; + +/** + * The one member of the i18next instance the bundle read needs. Optional, + * because outside a provider react-i18next hands back a placeholder object + * that has none — and then there is no bundle, only the authored copy. + */ +export interface TranslationResourceReader { + getResourceBundle?: (lng: string, ns: string) => unknown; +} + +/** + * The active language's `flows` group as a spec `TranslationBundle`, or + * `undefined` when the resource tree translates nothing for `flowName`. + * + * App translations sit under an app namespace at the top of that tree (`app` + * for a spec payload, whatever the payload named for an already-namespaced + * one), so the first namespace whose `flows` group addresses this flow is the + * one read. The bundle is keyed by `language` itself, and the resolvers are + * asked for `language` with no fallback chain: a string the active language + * does not carry falls back to the author's copy, never to a third locale. + */ +export function activeFlowsBundle( + i18n: TranslationResourceReader | undefined, + language: string, + flowName: string, +): TranslationBundle | undefined { + if (!flowName || typeof i18n?.getResourceBundle !== 'function') return undefined; + const tree = i18n.getResourceBundle(language, 'translation'); + if (!tree || typeof tree !== 'object') return undefined; + for (const namespace of Object.values(tree as Record)) { + const flows = (namespace as { flows?: unknown } | null)?.flows; + if (flows && typeof flows === 'object' && (flows as Record)[flowName]) { + return { [language]: { flows: flows as FlowsTranslation } }; + } + } + return undefined; +} + +/** A flow's translated labels in one language. Every member answers `undefined` where the bundle carries nothing. */ +export interface FlowLabelTranslations { + /** `flows..label`. */ + flowLabel?: string; + /** `flows..approvals..label`, for an `approval` node only. */ + stepLabel: (node: { id?: unknown; type?: unknown }) => string | undefined; +} + +/** + * The translated labels for `flowName` out of `bundle` in `language`, or + * `undefined` when there is no bundle (nothing to translate with). + * + * The flow label goes through the spec's `translateFlow`, the runner's + * resolution path; the step label is the spec-typed address + * `flows..approvals..label`, read for `approval` nodes only. + */ +export function flowLabelTranslations( + bundle: TranslationBundle | undefined, + flowName: string, + language: string, +): FlowLabelTranslations | undefined { + if (!bundle || !flowName) return undefined; + const flowLabel = translateFlow<{ name: string; label?: string }>({ name: flowName }, bundle, { locale: language }).label; + const approvals = bundle[language]?.flows?.[flowName]?.approvals; + return { + flowLabel: typeof flowLabel === 'string' && flowLabel ? flowLabel : undefined, + stepLabel: (node) => { + if (node.type !== 'approval' || typeof node.id !== 'string' || !node.id) return undefined; + const label = approvals?.[node.id]?.label; + return typeof label === 'string' && label ? label : undefined; + }, + }; +} + +/** + * {@link flowLabelTranslations} for `flowName` in the provider's active + * language. Recomputed on every render: a handful of property reads that + * follow the live resource tree and a language switch. + */ +export function useFlowLabelTranslations(flowName: string): FlowLabelTranslations | undefined { + const { i18n, language } = useObjectTranslation(); + return flowLabelTranslations(activeFlowsBundle(i18n, language, flowName), flowName, language); +} diff --git a/ui/packages/i18n/src/index.ts b/ui/packages/i18n/src/index.ts index d700130912c..eadda97eb1c 100644 --- a/ui/packages/i18n/src/index.ts +++ b/ui/packages/i18n/src/index.ts @@ -83,6 +83,18 @@ export type { TranslateFn } from './translateFn.js'; // Convention-based object/field label i18n export { useObjectLabel, useSafeFieldLabel } from './useObjectLabel.js'; +// An app's `flows` translation group and the flow labels a surface that draws a +// flow reads from it: the one reader for the console's runner, the Studio flow +// designer and the docs viewer's `type: flow` embed. +export { + activeFlowsBundle, + flowLabelTranslations, + useFlowLabelTranslations, + type FlowLabelTranslations, + type FlowsTranslation, + type TranslationResourceReader, +} from './flowLabels.js'; + // The record-named save message every record save surface toasts. export { recordSaveMessage, type RecordSaveMessageInput } from './recordSaveMessage.js'; From 1ffd04710413faea3b27edfa80c8507474f8a948 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 03:44:12 +0000 Subject: [PATCH 2/7] test(components): pin the flow embed's translated flow and approval-step labels and their authored fallback Claude-Session: https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1 Co-Authored-By: Claude --- .../src/__tests__/metadata-viewer.test.tsx | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/ui/packages/components/src/__tests__/metadata-viewer.test.tsx b/ui/packages/components/src/__tests__/metadata-viewer.test.tsx index d9cdaf66b52..5fca23543c9 100644 --- a/ui/packages/components/src/__tests__/metadata-viewer.test.tsx +++ b/ui/packages/components/src/__tests__/metadata-viewer.test.tsx @@ -11,6 +11,8 @@ import { describe, it, expect, vi } from 'vitest'; import { render, screen, waitFor, cleanup } from '@testing-library/react'; import { ComponentRegistry } from '@object-ui/core'; import { MetadataCtx } from '@object-ui/react'; +import { createI18n, I18nProvider, transformSpecTranslations } from '@object-ui/i18n'; +import type { TranslationData } from '@objectstack/spec/system'; import '../renderers/basic/metadata-viewer'; function metaCtx(getItem: (type: string, name: string) => Promise) { @@ -195,3 +197,78 @@ describe('element:metadata_viewer', () => { expect(screen.getByText(/Unknown metadata view type/i)).toBeTruthy(); }); }); + + +/** + * A `type: flow` embed names the flow and each step the spec lets a package + * translate in the reader's language: `flows..label` and an `approval` + * node's `flows..approvals..label`, read from the package bundle + * the host loaded, through the resolution the Studio flow designer uses. A step + * with no key (start, decision, notify, end) and a key the bundle does not + * carry fall back to the authored text. + */ +describe('element:metadata_viewer flow embed: package label translations (flows.FLOW.label, approvals.STEP.label)', () => { + const OPPORTUNITY_APPROVAL = { + name: 'opportunity_approval', + label: 'Large Deal Approval', + nodes: [ + { id: 'start', type: 'start', label: 'Start' }, + { id: 'get_opportunity', type: 'get_record', label: 'Get Opportunity' }, + { id: 'manager_review', type: 'approval', label: 'Sales Manager Review' }, + { id: 'check_high_value', type: 'decision', label: 'High Value (> $500K)?' }, + { id: 'director_signoff', type: 'approval', label: 'Sales Director Sign-off' }, + { id: 'notify_approved', type: 'notify', label: 'Email Owner — Approved' }, + { id: 'end', type: 'end', label: 'End' }, + ], + }; + + function zhCN(data: TranslationData) { + const instance = createI18n({ defaultLanguage: 'zh-CN', detectBrowserLanguage: false }); + instance.addResourceBundle('zh-CN', 'translation', transformSpecTranslations(data as Record), true, true); + return instance; + } + + function renderIn(data: TranslationData, flow = OPPORTUNITY_APPROVAL) { + const getItem = vi.fn(async () => flow); + return render( + + + , + ); + } + + it('draws the translated flow label and approval-step labels; a step with no key keeps its authored label', async () => { + renderIn({ + flows: { + opportunity_approval: { + label: '大额商机审批', + approvals: { manager_review: { label: '销售经理审核' }, director_signoff: { label: '销售总监签批' } }, + }, + }, + }); + await waitFor(() => expect(screen.getByText('大额商机审批')).toBeTruthy()); + expect(screen.queryByText('Large Deal Approval')).toBeNull(); + expect(screen.getByText('销售经理审核')).toBeTruthy(); + expect(screen.getByText('销售总监签批')).toBeTruthy(); + expect(screen.queryByText('Sales Manager Review')).toBeNull(); + expect(screen.queryByText('Sales Director Sign-off')).toBeNull(); + // start, decision, notify and end have no key in the spec's flows group. + for (const authored of ['Start', 'High Value (> $500K)?', 'Email Owner — Approved', 'End']) { + expect(screen.getByText(authored)).toBeTruthy(); + } + }); + + it('falls back to the authored text where the bundle carries no key', async () => { + // The flow is in the bundle, but neither its label nor one approval step is. + renderIn({ flows: { opportunity_approval: { approvals: { manager_review: { label: '销售经理审核' } } } } }); + await waitFor(() => expect(screen.getByText('Large Deal Approval')).toBeTruthy()); + expect(screen.getByText('销售经理审核')).toBeTruthy(); + expect(screen.getByText('Sales Director Sign-off')).toBeTruthy(); + cleanup(); + + // The bundle translates another flow only: everything stays authored. + renderIn({ flows: { other_flow: { label: '其他流程' } } }); + await waitFor(() => expect(screen.getByText('Large Deal Approval')).toBeTruthy()); + expect(screen.getByText('Sales Manager Review')).toBeTruthy(); + }); +}); From eccfc7d6382aeaad0ca83d1fb961483b83a2f2c7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 03:55:46 +0000 Subject: [PATCH 3/7] chore(changeset): flow embed label translations Claude-Session: https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1 Co-Authored-By: Claude --- .changeset/35979-flow-embed-labels.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .changeset/35979-flow-embed-labels.md diff --git a/.changeset/35979-flow-embed-labels.md b/.changeset/35979-flow-embed-labels.md new file mode 100644 index 00000000000..4a4ad40bd24 --- /dev/null +++ b/.changeset/35979-flow-embed-labels.md @@ -0,0 +1,15 @@ +--- +'@object-ui/components': patch +'@object-ui/i18n': patch +--- + +fix(components): a docs `type: flow` metadata embed names the flow and its approval steps in the reader's language + +Clause-②: no +Metadata-protocol: none + +A package can translate a flow's label (`flows..label`) and an approval step's label (`flows..approvals..label`). The flow runner and the Studio flow designer already showed both, but the docs viewer's `type: flow` embed (`element:metadata_viewer`) drew the authored text, so a zh-CN reader of a manual saw the English flow name and step names. The embed now reads the same bundle, through the same resolution, in the reader's language, and falls back to the authored text where the bundle carries no key. + +The spec has no key for a start, decision, notify or end node's label, so those steps still show the authored text. + +`@object-ui/i18n` now exports that resolution (`activeFlowsBundle`, `flowLabelTranslations`, `useFlowLabelTranslations` and their types), moved out of the console shell so the runner, the designer and the docs viewer share one reader of the `flows` group. From 7e3d2b7aaea22d5c8216da7a59165fcb4dd53dcf Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 06:00:15 +0000 Subject: [PATCH 4/7] refactor(i18n): move activeFlowsBundle to its own module beside the flow-label helpers The flows-bundle reader moves into @object-ui/i18n as flowsBundle.ts, kept whole, and flowLabels.ts imports it, so the Studio test's import and the package entry match the parallel move of the same reader. Claude-Session: https://claude.ai/code/session_01FEkQ5okniknzVVR3KTSVr1 Co-Authored-By: Claude --- .../previews/FlowCanvas.test.tsx | 4 +- .../previews/flow-label-translations.tsx | 2 +- ui/packages/i18n/src/flowLabels.ts | 67 +++--------------- ui/packages/i18n/src/flowsBundle.ts | 68 +++++++++++++++++++ ui/packages/i18n/src/index.ts | 23 ++++--- 5 files changed, 95 insertions(+), 69 deletions(-) create mode 100644 ui/packages/i18n/src/flowsBundle.ts diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx index 98bc62515df..26193c3f6c8 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/FlowCanvas.test.tsx @@ -10,14 +10,16 @@ import type { FlowProblem } from './flow-problems'; import { browserClick, browserDrag } from './__tests__/browserClick'; // FlowPreview reaches a dynamic `import('@objectstack/lint')`; pay its load at collection, not in a test's clock. import '@objectstack/lint'; -import { activeFlowsBundle, createI18n, flowLabelTranslations, I18nProvider, transformSpecTranslations } from '@object-ui/i18n'; +import { createI18n, I18nProvider, transformSpecTranslations } from '@object-ui/i18n'; import type { TranslationData } from '@objectstack/spec/system'; import { FlowPreview, FlowSelectionTitle, flowSelectionHeading } from './FlowPreview'; import { FlowLabelTranslationsProvider, + flowLabelTranslations, useFlowLabelTranslations, type FlowLabelTranslations, } from './flow-label-translations'; +import { activeFlowsBundle } from '@object-ui/i18n'; afterEach(cleanup); diff --git a/ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx b/ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx index 827e44695f1..9840ce7ea6b 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/previews/flow-label-translations.tsx @@ -26,7 +26,7 @@ import { type FlowLabelTranslations, } from '@object-ui/i18n'; -export { useFlowLabelTranslations, type FlowLabelTranslations } from '@object-ui/i18n'; +export { flowLabelTranslations, useFlowLabelTranslations, type FlowLabelTranslations } from '@object-ui/i18n'; /** * The flow label of any flow, by name, for a surface that lists many: the diff --git a/ui/packages/i18n/src/flowLabels.ts b/ui/packages/i18n/src/flowLabels.ts index 7b46c2cc80e..5f1bac2999e 100644 --- a/ui/packages/i18n/src/flowLabels.ts +++ b/ui/packages/i18n/src/flowLabels.ts @@ -7,72 +7,27 @@ */ /** - * An app's `flows` translation group, read back out of the i18next resource - * tree the host already loaded, and the two flow labels a surface that DRAWS a - * flow resolves from it: the flow's own label (`flows..label`) and an - * `approval` node's step label (`flows..approvals..label`). + * The two flow labels a surface that DRAWS a flow resolves from the app's + * `flows` translation group (`activeFlowsBundle`, `flowsBundle.ts`): the + * flow's own label (`flows..label`) and an `approval` node's step label + * (`flows..approvals..label`). * - * This is the ONE reader of that group in the UI. It lives here, beside the - * provider whose resource tree it reads, so every surface reads it the same - * way: the console's `FlowRunner` and flow-launch hosts, the Studio flow - * designer, and the docs viewer's `type: flow` embed - * (`element:metadata_viewer`). None of them can disagree about where the - * bundle lives or what a flow is called. - * - * The provider's `loadLanguage` hands the app's translation payload to - * i18next (`transformSpecTranslations` forwards `flows` verbatim under the app - * namespace), so there is no second loader. + * The Studio flow designer and the docs viewer's `type: flow` embed + * (`element:metadata_viewer`) both read them here, and the flow label goes + * through the spec's `translateFlow`, the runner's resolution path, so no two + * surfaces can disagree about what a flow or a step is called. * * Only those two keys exist in the spec's `flows` group for a label a flow - * drawing shows. A decision, notify, start or end node's label and an edge + * drawing shows. A start, decision, notify or end node's label and an edge * label have no key, so they stay the authored text. * * Display only: nothing here rewrites the flow, so an editor keeps working on * the authored label. */ -import { translateFlow, type TranslationBundle, type TranslationData } from '@objectstack/spec/system'; +import { translateFlow, type TranslationBundle } from '@objectstack/spec/system'; import { useObjectTranslation } from './provider.js'; - -/** The `flows` group of a spec `TranslationData` — typed by the spec, so the address below is checked against it. */ -export type FlowsTranslation = NonNullable; - -/** - * The one member of the i18next instance the bundle read needs. Optional, - * because outside a provider react-i18next hands back a placeholder object - * that has none — and then there is no bundle, only the authored copy. - */ -export interface TranslationResourceReader { - getResourceBundle?: (lng: string, ns: string) => unknown; -} - -/** - * The active language's `flows` group as a spec `TranslationBundle`, or - * `undefined` when the resource tree translates nothing for `flowName`. - * - * App translations sit under an app namespace at the top of that tree (`app` - * for a spec payload, whatever the payload named for an already-namespaced - * one), so the first namespace whose `flows` group addresses this flow is the - * one read. The bundle is keyed by `language` itself, and the resolvers are - * asked for `language` with no fallback chain: a string the active language - * does not carry falls back to the author's copy, never to a third locale. - */ -export function activeFlowsBundle( - i18n: TranslationResourceReader | undefined, - language: string, - flowName: string, -): TranslationBundle | undefined { - if (!flowName || typeof i18n?.getResourceBundle !== 'function') return undefined; - const tree = i18n.getResourceBundle(language, 'translation'); - if (!tree || typeof tree !== 'object') return undefined; - for (const namespace of Object.values(tree as Record)) { - const flows = (namespace as { flows?: unknown } | null)?.flows; - if (flows && typeof flows === 'object' && (flows as Record)[flowName]) { - return { [language]: { flows: flows as FlowsTranslation } }; - } - } - return undefined; -} +import { activeFlowsBundle } from './flowsBundle.js'; /** A flow's translated labels in one language. Every member answers `undefined` where the bundle carries nothing. */ export interface FlowLabelTranslations { diff --git a/ui/packages/i18n/src/flowsBundle.ts b/ui/packages/i18n/src/flowsBundle.ts new file mode 100644 index 00000000000..cd6d4436fc8 --- /dev/null +++ b/ui/packages/i18n/src/flowsBundle.ts @@ -0,0 +1,68 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * The app's `flows` translation group, read back out of the i18next resource + * tree the host already loaded — the ONE reader of that group in the UI. + * + * Every surface that names a flow in the reader's language reads it through + * this module, so none can disagree about where the bundle lives: the + * console's `FlowRunner` (the paused screen's field copy and option labels, + * the flow's label, the resume's terminal toasts), the two flow-LAUNCH hosts + * through `launchConsoleFlow` (objectui#12075), and, through + * `flowLabelTranslations` (`flowLabels.ts`), the Studio flow designer and the + * docs viewer's `type: flow` embed. It lives here rather than in + * `@object-ui/app-shell` because the embed's package does not depend on the + * console. + * + * The provider's `loadLanguage` hands the app's translation payload to + * i18next (`transformSpecTranslations` forwards `flows` verbatim under the app + * namespace), so there is no second loader. + */ + +import type { TranslationBundle, TranslationData } from '@objectstack/spec/system'; + +/** The `flows` group of a spec `TranslationData` — typed by the spec, so the address below is checked against it. */ +export type FlowsTranslation = NonNullable; + +/** + * The one member of the i18next instance the bundle read needs. Optional, + * because outside a provider react-i18next hands back a placeholder object + * that has none — and then there is no bundle, only the authored copy. + */ +export interface TranslationResourceReader { + getResourceBundle?: (lng: string, ns: string) => unknown; +} + +/** + * The active language's `flows` group as a spec `TranslationBundle`, or + * `undefined` when the resource tree translates nothing for `flowName`. + * + * App translations sit under an app namespace at the top of that tree (`app` + * for a spec payload, whatever the payload named for an already-namespaced + * one), so the first namespace whose `flows` group addresses this flow is the + * one read. The bundle is keyed by `language` itself, and the resolvers are + * asked for `language` with no fallback chain: a string the active language + * does not carry falls back to the author's copy, never to a third locale. + */ +export function activeFlowsBundle( + i18n: TranslationResourceReader | undefined, + language: string, + flowName: string, +): TranslationBundle | undefined { + if (!flowName || typeof i18n?.getResourceBundle !== 'function') return undefined; + const tree = i18n.getResourceBundle(language, 'translation'); + if (!tree || typeof tree !== 'object') return undefined; + for (const namespace of Object.values(tree as Record)) { + const flows = (namespace as { flows?: unknown } | null)?.flows; + if (flows && typeof flows === 'object' && (flows as Record)[flowName]) { + return { [language]: { flows: flows as FlowsTranslation } }; + } + } + return undefined; +} diff --git a/ui/packages/i18n/src/index.ts b/ui/packages/i18n/src/index.ts index eadda97eb1c..2c7d040c203 100644 --- a/ui/packages/i18n/src/index.ts +++ b/ui/packages/i18n/src/index.ts @@ -83,17 +83,9 @@ export type { TranslateFn } from './translateFn.js'; // Convention-based object/field label i18n export { useObjectLabel, useSafeFieldLabel } from './useObjectLabel.js'; -// An app's `flows` translation group and the flow labels a surface that draws a -// flow reads from it: the one reader for the console's runner, the Studio flow -// designer and the docs viewer's `type: flow` embed. -export { - activeFlowsBundle, - flowLabelTranslations, - useFlowLabelTranslations, - type FlowLabelTranslations, - type FlowsTranslation, - type TranslationResourceReader, -} from './flowLabels.js'; +// The flow labels a surface that draws a flow reads from the app's `flows` +// group: the Studio flow designer and the docs viewer's `type: flow` embed. +export { flowLabelTranslations, useFlowLabelTranslations, type FlowLabelTranslations } from './flowLabels.js'; // The record-named save message every record save surface toasts. export { recordSaveMessage, type RecordSaveMessageInput } from './recordSaveMessage.js'; @@ -203,3 +195,12 @@ export { // grids and the timeline's week buckets read it from the tag they format with, // so the week starts where the locale says and never on a hard-coded day. export { firstDayOfWeek, type WeekdayIndex } from './utils/index.js'; + +// The app's `flows` translation group, read back out of the loaded resource +// tree: the ONE reader every surface that names a flow goes through — the +// console's flow runner and designer, and the docs viewer's flow embed. +export { + activeFlowsBundle, + type FlowsTranslation, + type TranslationResourceReader, +} from './flowsBundle.js'; From 10f53529e4f2343e7d59ba01324fe8c86f8aba19 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 13:42:44 +0000 Subject: [PATCH 5/7] chore(changeset): the flow embed changeset names only the flow-label helpers this PR adds Claude-Session: https://claude.ai/code/session_01QsR2jV3scu6UYPb42n5okQ Co-authored-by: Claude --- .changeset/35979-flow-embed-labels.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/35979-flow-embed-labels.md b/.changeset/35979-flow-embed-labels.md index 4a4ad40bd24..33e81468b49 100644 --- a/.changeset/35979-flow-embed-labels.md +++ b/.changeset/35979-flow-embed-labels.md @@ -10,6 +10,6 @@ Metadata-protocol: none A package can translate a flow's label (`flows..label`) and an approval step's label (`flows..approvals..label`). The flow runner and the Studio flow designer already showed both, but the docs viewer's `type: flow` embed (`element:metadata_viewer`) drew the authored text, so a zh-CN reader of a manual saw the English flow name and step names. The embed now reads the same bundle, through the same resolution, in the reader's language, and falls back to the authored text where the bundle carries no key. -The spec has no key for a start, decision, notify or end node's label, so those steps still show the authored text. +The spec has no key yet for a start, decision, notify or end node's label, so those steps still show the authored text. -`@object-ui/i18n` now exports that resolution (`activeFlowsBundle`, `flowLabelTranslations`, `useFlowLabelTranslations` and their types), moved out of the console shell so the runner, the designer and the docs viewer share one reader of the `flows` group. +`@object-ui/i18n` now also exports the flow-label resolution (`flowLabelTranslations`, `useFlowLabelTranslations` and the `FlowLabelTranslations` type), moved out of the Studio flow designer and built on the `activeFlowsBundle` reader that package already exports, so the runner, the designer and the docs viewer share one reader of the `flows` group. From 599975314ab00f37bb3ff72ae93020a2f6be943e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 14:38:36 +0000 Subject: [PATCH 6/7] chore(changeset): the flow embed changeset names the branch targets' translated step label Claude-Session: https://claude.ai/code/session_01QsR2jV3scu6UYPb42n5okQ Co-authored-by: Claude --- .changeset/35979-flow-embed-labels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/35979-flow-embed-labels.md b/.changeset/35979-flow-embed-labels.md index 33e81468b49..cde51ed8df7 100644 --- a/.changeset/35979-flow-embed-labels.md +++ b/.changeset/35979-flow-embed-labels.md @@ -8,7 +8,7 @@ fix(components): a docs `type: flow` metadata embed names the flow and its appro Clause-②: no Metadata-protocol: none -A package can translate a flow's label (`flows..label`) and an approval step's label (`flows..approvals..label`). The flow runner and the Studio flow designer already showed both, but the docs viewer's `type: flow` embed (`element:metadata_viewer`) drew the authored text, so a zh-CN reader of a manual saw the English flow name and step names. The embed now reads the same bundle, through the same resolution, in the reader's language, and falls back to the authored text where the bundle carries no key. +A package can translate a flow's label (`flows..label`) and an approval step's label (`flows..approvals..label`). The flow runner and the Studio flow designer already showed both, but the docs viewer's `type: flow` embed (`element:metadata_viewer`) drew the authored text, so a zh-CN reader of a manual saw the English flow name and step names. The embed now reads the same bundle, through the same resolution, in the reader's language, and falls back to the authored text where the bundle carries no key. A decision's branch list names the approval step a branch leads to by the same translated label. The spec has no key yet for a start, decision, notify or end node's label, so those steps still show the authored text. From 38fa51fb3e03d7ea5be0381b9dc3fd06a5c26c9c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 15:09:26 +0000 Subject: [PATCH 7/7] chore(changeset): declare the flow-label helpers as a widening of @object-ui/i18n's public exports Claude-Session: https://claude.ai/code/session_01QsR2jV3scu6UYPb42n5okQ Co-authored-by: Claude --- .changeset/35979-flow-embed-labels.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/35979-flow-embed-labels.md b/.changeset/35979-flow-embed-labels.md index cde51ed8df7..7a968366dbb 100644 --- a/.changeset/35979-flow-embed-labels.md +++ b/.changeset/35979-flow-embed-labels.md @@ -5,11 +5,11 @@ fix(components): a docs `type: flow` metadata embed names the flow and its approval steps in the reader's language -Clause-②: no +Clause-②: yes (widening) Metadata-protocol: none A package can translate a flow's label (`flows..label`) and an approval step's label (`flows..approvals..label`). The flow runner and the Studio flow designer already showed both, but the docs viewer's `type: flow` embed (`element:metadata_viewer`) drew the authored text, so a zh-CN reader of a manual saw the English flow name and step names. The embed now reads the same bundle, through the same resolution, in the reader's language, and falls back to the authored text where the bundle carries no key. A decision's branch list names the approval step a branch leads to by the same translated label. The spec has no key yet for a start, decision, notify or end node's label, so those steps still show the authored text. -`@object-ui/i18n` now also exports the flow-label resolution (`flowLabelTranslations`, `useFlowLabelTranslations` and the `FlowLabelTranslations` type), moved out of the Studio flow designer and built on the `activeFlowsBundle` reader that package already exports, so the runner, the designer and the docs viewer share one reader of the `flows` group. +`@object-ui/i18n` has new public exports for the flow-label resolution (`flowLabelTranslations`, `useFlowLabelTranslations` and the `FlowLabelTranslations` type), moved out of the Studio flow designer and built on the `activeFlowsBundle` reader that package already exports, so the runner, the designer and the docs viewer share one reader of the `flows` group.