Skip to content

Commit 8a62e09

Browse files
committed
wip(ui): localise the console's leftover literals (#25916 round 3)
Claude-Session: https://claude.ai/code/session_01C6T942afhqAP5w9XBmfTDC Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0c37228 commit 8a62e09

17 files changed

Lines changed: 428 additions & 29 deletions

File tree

‎ui/apps/console/src/pages/developer/FlowRunsPage.tsx‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ import {
5656
Play, Loader2, CheckCircle2, XCircle, Clock, AlertCircle, RefreshCw, Workflow,
5757
} from 'lucide-react';
5858

59+
/**
60+
* A panel's error: the message a call threw, or the client method the panel
61+
* needs and this client lacks. The method is kept by name and worded at render,
62+
* so the diagnostic reads in the viewer's locale (#25916).
63+
*/
64+
type PanelError = { message: string } | { unavailable: string };
65+
66+
function panelErrorText(t: ReturnType<typeof useObjectTranslation>['t'], error: PanelError): string {
67+
return 'unavailable' in error
68+
? t('console.developer.flowRuns.clientMethodUnavailable', {
69+
defaultValue: '{{method}} is not available on this client',
70+
method: error.unavailable,
71+
})
72+
: error.message;
73+
}
74+
5975
interface FlowVariable {
6076
name: string;
6177
type: string;
@@ -197,13 +213,13 @@ export function FlowRunsPage() {
197213

198214
const [flows, setFlows] = useState<FlowItem[]>([]);
199215
const [flowsLoading, setFlowsLoading] = useState(true);
200-
const [flowsError, setFlowsError] = useState<string | null>(null);
216+
const [flowsError, setFlowsError] = useState<PanelError | null>(null);
201217
const [selectedFlowName, setSelectedFlowName] = useState<string>('');
202218
const [refreshRuns, setRefreshRuns] = useState(0);
203219

204220
const loadFlows = useCallback(async () => {
205221
if (!client?.meta?.getItems) {
206-
setFlowsError('meta.getItems is not available on this client');
222+
setFlowsError({ unavailable: 'meta.getItems' });
207223
setFlowsLoading(false);
208224
return;
209225
}
@@ -233,7 +249,7 @@ export function FlowRunsPage() {
233249
setSelectedFlowName(normalized[0].name);
234250
}
235251
} catch (e: any) {
236-
setFlowsError(e?.message ?? String(e));
252+
setFlowsError({ message: e?.message ?? String(e) });
237253
} finally {
238254
setFlowsLoading(false);
239255
}
@@ -276,7 +292,7 @@ export function FlowRunsPage() {
276292
<CardContent>
277293
{flowsLoading && <Skeleton className="h-9 w-72" />}
278294
{flowsError && (
279-
<p className="text-sm text-red-500 font-mono break-all">{flowsError}</p>
295+
<p className="text-sm text-red-500 font-mono break-all">{panelErrorText(t, flowsError)}</p>
280296
)}
281297
{!flowsLoading && !flowsError && flows.length === 0 && (
282298
<p className="text-sm text-muted-foreground">{t('console.developer.flowRuns.noFlows', { defaultValue: 'No flow definitions found.' })}</p>
@@ -335,7 +351,7 @@ function FlowTestRunner({
335351
const [values, setValues] = useState<Record<string, string>>({});
336352
const [running, setRunning] = useState(false);
337353
const [result, setResult] = useState<any>(null);
338-
const [error, setError] = useState<string | null>(null);
354+
const [error, setError] = useState<PanelError | null>(null);
339355
// The paused screen a test run stopped at — driven to completion by
340356
// <FlowRunner>, exactly as a `type: 'flow'` action would.
341357
const [screenFlow, setScreenFlow] = useState<ScreenFlowState | null>(null);
@@ -351,7 +367,7 @@ function FlowTestRunner({
351367

352368
const handleRun = async () => {
353369
if (!client?.automation?.execute) {
354-
setError('automation.execute is not available on this client');
370+
setError({ unavailable: 'automation.execute' });
355371
return;
356372
}
357373
setRunning(true);
@@ -376,7 +392,7 @@ function FlowTestRunner({
376392
}
377393
onExecuted?.();
378394
} catch (e: any) {
379-
setError(e?.message ?? String(e));
395+
setError({ message: e?.message ?? String(e) });
380396
} finally {
381397
setRunning(false);
382398
}
@@ -455,7 +471,7 @@ function FlowTestRunner({
455471
</Badge>
456472
)}
457473
</div>
458-
{error && <p className="text-sm text-red-500 font-mono break-all">{error}</p>}
474+
{error && <p className="text-sm text-red-500 font-mono break-all">{panelErrorText(t, error)}</p>}
459475
{/* A run left paused (the runner was dismissed) can be reopened —
460476
the suspension is durable, so the screen is still waiting. */}
461477
{result?.status === 'paused' && result?.screen && result?.runId && !screenFlow && (
@@ -518,7 +534,7 @@ function FlowRunsPanel({
518534
const displayLocale = useDisplayLocale();
519535
const [runs, setRuns] = useState<RunSummary[]>([]);
520536
const [loading, setLoading] = useState(true);
521-
const [error, setError] = useState<string | null>(null);
537+
const [error, setError] = useState<PanelError | null>(null);
522538

523539
const [openRunId, setOpenRunId] = useState<string | null>(null);
524540
const [runDetail, setRunDetail] = useState<any>(null);
@@ -527,7 +543,7 @@ function FlowRunsPanel({
527543

528544
const loadRuns = useCallback(async () => {
529545
if (!client?.automation?.listRuns) {
530-
setError('automation.listRuns is not available on this client');
546+
setError({ unavailable: 'automation.listRuns' });
531547
setLoading(false);
532548
return;
533549
}
@@ -538,7 +554,7 @@ function FlowRunsPanel({
538554
const items: RunSummary[] = Array.isArray(res) ? res : (res?.items ?? res?.runs ?? []);
539555
setRuns(items);
540556
} catch (e: any) {
541-
setError(e?.message ?? String(e));
557+
setError({ message: e?.message ?? String(e) });
542558
} finally {
543559
setLoading(false);
544560
}
@@ -585,7 +601,7 @@ function FlowRunsPanel({
585601
</div>
586602
)}
587603
{!loading && error && (
588-
<p className="text-sm text-red-500 font-mono break-all">{error}</p>
604+
<p className="text-sm text-red-500 font-mono break-all">{panelErrorText(t, error)}</p>
589605
)}
590606
{!loading && !error && runs.length === 0 && (
591607
<p className="text-sm text-muted-foreground py-6 text-center">

‎ui/packages/app-shell/src/views/ObjectView.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,7 +3176,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
31763176
const dims: string[] = Array.isArray(chartConfig.dimensions) ? chartConfig.dimensions : [];
31773177
const vals: string[] = Array.isArray(chartConfig.values) ? chartConfig.values : [];
31783178
return withViewTabs(
3179-
<Suspense key={identityKey} fallback={<div className="p-4 text-sm text-muted-foreground">Loading chart…</div>}>
3179+
<Suspense key={identityKey} fallback={<div className="p-4 text-sm text-muted-foreground">{t('chart.loading')}</div>}>
31803180
<ObjectChart
31813181
dataSource={ds}
31823182
schema={{
@@ -3208,7 +3208,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
32083208
// `chart-missing-category-axis`) instead of aggregating on a name
32093209
// nobody wrote. ⛔ Do not restore a floor here.
32103210
return withViewTabs(
3211-
<Suspense key={identityKey} fallback={<div className="p-4 text-sm text-muted-foreground">Loading chart…</div>}>
3211+
<Suspense key={identityKey} fallback={<div className="p-4 text-sm text-muted-foreground">{t('chart.loading')}</div>}>
32123212
<ObjectChart
32133213
dataSource={ds}
32143214
schema={{

‎ui/packages/app-shell/src/views/metadata-admin/ResourceEditPage.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,9 +3581,9 @@ function ReferencesPanel({
35813581
<table className="w-full text-sm">
35823582
<thead className="bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground">
35833583
<tr>
3584-
<th className="px-3 py-2 text-left">From type</th>
3585-
<th className="px-3 py-2 text-left">From name</th>
3586-
<th className="px-3 py-2 text-left">Path</th>
3584+
<th className="px-3 py-2 text-left">{t('engine.edit.refsColFromType', locale)}</th>
3585+
<th className="px-3 py-2 text-left">{t('engine.edit.refsColFromName', locale)}</th>
3586+
<th className="px-3 py-2 text-left">{t('engine.edit.refsColPath', locale)}</th>
35873587
</tr>
35883588
</thead>
35893589
<tbody className="divide-y">

‎ui/packages/app-shell/src/views/metadata-admin/i18n.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,10 @@ const ENGINE_STRINGS_EN: Record<string, string> = {
21722172
'engine.edit.refsScanning': 'Scanning references…',
21732173
'engine.edit.refsEmptyTitle': 'No references found',
21742174
'engine.edit.refsEmptyDesc': 'Nothing in the metadata graph points at this item. Safe to delete.',
2175+
// #25916 — the references table's column headers.
2176+
'engine.edit.refsColFromType': 'From type',
2177+
'engine.edit.refsColFromName': 'From name',
2178+
'engine.edit.refsColPath': 'Path',
21752179
// …and its FAILED state (objectui#5110), which must never be confusable with
21762180
// the empty one above: the copy states that the check did not complete and
21772181
// deliberately makes no claim — in either direction — about whether deleting
@@ -5798,6 +5802,9 @@ const ENGINE_STRINGS_ZH: Record<string, string> = {
57985802
'engine.edit.refsScanning': '正在扫描引用…',
57995803
'engine.edit.refsEmptyTitle': '未找到引用',
58005804
'engine.edit.refsEmptyDesc': '元数据图中没有任何项指向它,可以安全删除。',
5805+
'engine.edit.refsColFromType': '来源类型',
5806+
'engine.edit.refsColFromName': '来源名称',
5807+
'engine.edit.refsColPath': '路径',
58015808
// …以及它的失败态(objectui#5110):必须与上面的空态不可混淆 —— 文案只说明检查
58025809
// 没有完成,对「删除是否安全」不做任何方向的断言,因为这个问题根本没有被回答。
58035810
// 后续改写务必保留这一性质;「未找到引用」正是此状态要避免的那句话。
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* #25916, third pass — two renderers in this package drew English literals
11+
* whatever the session's language.
12+
*
13+
* - `data-table`: the hover "open record" affordance's title and the inline
14+
* edit row's cancel / save buttons (`table.openRecord`,
15+
* `table.cancelChanges`, `table.saveRow`);
16+
* - the `kind:'react'` page renderer: its capability notice, its empty-source
17+
* refusal, its loading line and its error titles (`reactPage.*`).
18+
*
19+
* What this file pins, through the real renderers and a real `I18nProvider`:
20+
* - under zh each surface draws the zh pack's row (expectations read from the
21+
* pack, guarded as real zh rows);
22+
* - a sentence with an inline `<code>` is ONE translated string: the code
23+
* sits where the zh string put it, and no `{{slot}}` or private-use mark
24+
* is left in the text;
25+
* - control: with no provider each surface still reads its English.
26+
*/
27+
import { describe, it, expect, afterEach } from 'vitest';
28+
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';
29+
import React from 'react';
30+
import { CAP_REACT_PAGES, ComponentRegistry, disableCapability, enableCapability } from '@object-ui/core';
31+
import { AdapterCtx, SchemaRenderer } from '@object-ui/react';
32+
import { I18nProvider } from '@object-ui/i18n';
33+
import { builtInLocales } from '@object-ui/i18n/locales';
34+
import type { PageDocumentNode } from '@object-ui/types';
35+
// Registers the renderers at module scope, NOT inside a `beforeAll`; see
36+
// object-ui/no-dynamic-import-in-test-hook (objectui#3010/#3021).
37+
import '../renderers';
38+
39+
const { zh, en } = builtInLocales;
40+
41+
/** No `{{slot}}` and no private-use slot mark survives into the rendered text. */
42+
const LEAK = /\{\{|[\u{E000}-\u{F8FF}]/u;
43+
44+
function withLanguage(element: React.ReactElement, language: 'zh' | null) {
45+
return render(
46+
language ? (
47+
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }} persistLanguage={false}>
48+
{element}
49+
</I18nProvider>
50+
) : (
51+
element
52+
),
53+
);
54+
}
55+
56+
const ALPHA = { id: 'a', name: 'Alpha', qty: 10 };
57+
58+
function DataTable({ onRowClick }: { onRowClick?: () => void }) {
59+
const Table = ComponentRegistry.get('data-table')!;
60+
const schema = {
61+
type: 'data-table',
62+
editable: true,
63+
singleClickEdit: true,
64+
rowActions: true,
65+
showRowNumbers: true,
66+
columns: [
67+
{ header: 'Task', accessorKey: 'name', editable: false },
68+
{ header: 'Estimate', accessorKey: 'qty', type: 'number' },
69+
],
70+
data: [ALPHA],
71+
onRowSave: async () => undefined,
72+
...(onRowClick ? { onRowClick } : {}),
73+
} as any;
74+
return <Table schema={schema} />;
75+
}
76+
77+
/** Stage an edit on Alpha's estimate, so the row draws its cancel / save buttons. */
78+
function stageEdit(container: HTMLElement) {
79+
const cell = container.querySelectorAll('tbody tr td')[2] as HTMLElement;
80+
fireEvent.click(cell);
81+
const input = cell.querySelector('input') as HTMLInputElement;
82+
fireEvent.change(input, { target: { value: '11' } });
83+
fireEvent.blur(input);
84+
}
85+
86+
const PAGE = (source: string): PageDocumentNode => ({
87+
type: 'home',
88+
kind: 'react',
89+
name: 'locale_page',
90+
label: 'Locale page',
91+
source,
92+
});
93+
94+
function ReactPage({ source }: { source: string }) {
95+
return (
96+
<AdapterCtx.Provider value={{ find: async () => [] } as any}>
97+
<SchemaRenderer schema={PAGE(source)} />
98+
</AdapterCtx.Provider>
99+
);
100+
}
101+
102+
afterEach(() => {
103+
cleanup();
104+
disableCapability(CAP_REACT_PAGES);
105+
});
106+
107+
describe('renderer copy under zh (#25916)', () => {
108+
it('guard: the zh values read below are real zh rows, not English copies', () => {
109+
for (const [zhValue, enValue] of [
110+
[zh.table.openRecord, en.table.openRecord],
111+
[zh.table.cancelChanges, en.table.cancelChanges],
112+
[zh.table.saveRow, en.table.saveRow],
113+
[zh.reactPage.disabledTitle, en.reactPage.disabledTitle],
114+
[zh.reactPage.disabledBody, en.reactPage.disabledBody],
115+
[zh.reactPage.sourceRequired, en.reactPage.sourceRequired],
116+
]) {
117+
expect(zhValue).not.toBe(enValue);
118+
expect(zhValue).toMatch(/\p{Script=Han}/u);
119+
}
120+
});
121+
122+
it('data-table: the open affordance and the edited row buttons are titled in zh', () => {
123+
const { container } = withLanguage(<DataTable onRowClick={() => undefined} />, 'zh');
124+
expect(screen.getByTestId('row-expand-button').getAttribute('title')).toBe(zh.table.openRecord);
125+
stageEdit(container);
126+
const row = container.querySelector('tbody tr') as HTMLElement;
127+
expect(within(row).getByTitle(zh.table.cancelChanges)).toBeTruthy();
128+
expect(within(row).getByTitle(zh.table.saveRow)).toBeTruthy();
129+
});
130+
131+
it('react page, capability off: the notice is zh, its three <code> chips where the zh string put them', async () => {
132+
const { container } = withLanguage(<ReactPage source="function Page() { return null; }" />, 'zh');
133+
expect(await screen.findByText(zh.reactPage.disabledTitle)).toBeTruthy();
134+
const flag = screen.getByText('OS_PAGE_REACT_ENABLED=true', { selector: 'code' });
135+
expect(flag.parentElement!.textContent).toBe(
136+
zh.reactPage.disabledBody
137+
.replace('{{kind}}', "kind:'react'")
138+
.replace('{{flag}}', 'OS_PAGE_REACT_ENABLED=true')
139+
.replace('{{call}}', "enableCapability('react-pages')"),
140+
);
141+
expect(container.textContent).not.toMatch(LEAK);
142+
});
143+
144+
it('react page, capability on: an empty source is refused in zh, its chips in place', async () => {
145+
enableCapability(CAP_REACT_PAGES);
146+
const { container } = withLanguage(<ReactPage source=" " />, 'zh');
147+
const source = await screen.findByText('source', { selector: 'code' });
148+
expect(source.parentElement!.textContent).toBe(
149+
zh.reactPage.sourceRequired.replace('{{kind}}', "kind:'react'").replace('{{source}}', 'source'),
150+
);
151+
expect(container.textContent).not.toMatch(LEAK);
152+
});
153+
});
154+
155+
describe('control: with no provider each surface still reads its English (#25916)', () => {
156+
it('data-table', () => {
157+
const { container } = withLanguage(<DataTable onRowClick={() => undefined} />, null);
158+
expect(screen.getByTestId('row-expand-button').getAttribute('title')).toBe('Open record');
159+
stageEdit(container);
160+
expect(screen.getByTitle('Cancel changes')).toBeTruthy();
161+
expect(screen.getByTitle('Save row')).toBeTruthy();
162+
});
163+
164+
it('react page notice', async () => {
165+
withLanguage(<ReactPage source="function Page() { return null; }" />, null);
166+
const flag = await screen.findByText('OS_PAGE_REACT_ENABLED=true', { selector: 'code' });
167+
expect(screen.getByText('React pages are disabled on this deployment')).toBeTruthy();
168+
expect(flag.parentElement!.textContent).toBe(
169+
"kind:'react' pages execute author JavaScript directly in the application, so they are off unless the deployment turns them on. An operator whose page authors are trusted sets OS_PAGE_REACT_ENABLED=true on the server (a host embedding the renderer calls enableCapability('react-pages')).",
170+
);
171+
});
172+
173+
it('react page empty source', async () => {
174+
enableCapability(CAP_REACT_PAGES);
175+
withLanguage(<ReactPage source=" " />, null);
176+
const source = await screen.findByText('source', { selector: 'code' });
177+
expect(source.parentElement!.textContent).toBe("A kind:'react' page requires a non-empty source.");
178+
});
179+
});

‎ui/packages/components/src/renderers/complex/data-table.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ const TABLE_DEFAULT_TRANSLATIONS: Record<string, string> = {
328328
'table.rowActions': 'Row actions',
329329
'table.edit': 'Edit',
330330
'table.delete': 'Delete',
331+
// #25916 — the hover open affordance and the inline-edit row buttons.
332+
'table.openRecord': 'Open record',
333+
'table.cancelChanges': 'Cancel changes',
334+
'table.saveRow': 'Save row',
331335
'common.actions': 'Actions',
332336
// objectui#10625 — the inline date editors' notice for a stored value
333337
// written on a day that does not exist. The SAME keys `DateField` /
@@ -3575,7 +3579,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
35753579
// plain one.
35763580
schema.onRowClick?.(row, e);
35773581
}}
3578-
title="Open record"
3582+
title={t('table.openRecord')}
35793583
>
35803584
<span>{t('table.open')}</span>
35813585
<ChevronRight className="h-3 w-3" />
@@ -3947,7 +3951,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
39473951
size="icon"
39483952
onClick={() => cancelRowChanges(rowKey)}
39493953
disabled={isSaving}
3950-
title="Cancel changes"
3954+
title={t('table.cancelChanges')}
39513955
>
39523956
<X className="h-4 w-4" />
39533957
</Button>
@@ -3956,7 +3960,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
39563960
size="icon"
39573961
onClick={() => saveRow(rowKey)}
39583962
disabled={isSaving}
3959-
title="Save row"
3963+
title={t('table.saveRow')}
39603964
>
39613965
<Save className="h-4 w-4 text-green-600" />
39623966
</Button>

0 commit comments

Comments
 (0)