Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 8033ad1

Browse files
os-zhuangos-support-aiclaude
authored
fix(i18n): built-in record-detail tabs and two landmark names speak the session locale (objectui#4645) (#8806)
`buildDefaultPageSchema` synthesizes the record-detail tab strip with plain English tokens on the nodes (`Details`, `Related`, `Attachments`, `Activity`, `History`, `Approvals`), and three of its own comments said those tokens "localize through the tab strip's KNOWN_LABEL_DICT". That dict shipped exactly two arms — `zh-CN` and `zh-TW` — so the claim held for Chinese and silently failed for the eight other shipped packs. Every one of those strings was already in all ten packs; the strip simply never asked. `translateLabel` now consults `KNOWN_LABEL_KEYS` after the exact-locale dict, which stays first because `zh-TW` has no pack of its own (i18next resolves it to the Simplified `zh` resource) and because it carries tokens no pack does. `page:accordion` reads the same lookup. The two `aria-label`s that were English in every locale — `HeaderHighlight`'s `Record highlights` and `RecordActivityTimeline`'s `Discussion` — now route through the bundle. `detail.discussion` already existed in all ten packs; `detail.highlightsLabel` is the single new key, added to all ten and mirrored byte-identically into `DETAIL_DEFAULT_TRANSLATIONS`. Claude-Session: https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH Co-authored-by: os-zhuang <support@objectstack.ai> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 326a6e5 commit 8033ad1

18 files changed

Lines changed: 434 additions & 21 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/plugin-detail': patch
4+
'@object-ui/i18n': minor
5+
---
6+
7+
The built-in record-detail tab labels and the last two English landmark names now speak the session locale (objectui#4645).
8+
9+
`buildDefaultPageSchema` synthesizes the record-detail tab strip with plain
10+
English tokens on the nodes (`Details`, `Related`, `Attachments`, `Activity`,
11+
`History`, `Approvals`), and three of its own comments said those tokens
12+
"localize through the tab strip's `KNOWN_LABEL_DICT`". That dict shipped
13+
exactly two arms — `zh-CN` and `zh-TW` — so the claim held for Chinese and
14+
silently failed for the eight other shipped packs: a ja-JP or es-ES record
15+
detail rendered `Details / Related / Attachments` inside otherwise fully
16+
localized chrome, measured in a real browser on `@objectstack/console` 17.0.0
17+
GA and re-measured red on current `main`.
18+
19+
Every one of those strings was already in all ten packs (`detail.details`,
20+
`detail.related`, `detail.activity`, `detail.history`, `detail.attachments`,
21+
`detail.approvalsPanelTitle`); the strip simply never asked. It asks now,
22+
BEHIND the exact-locale dict, which stays first because `zh-TW` has no pack of
23+
its own — i18next resolves it to the Simplified `zh` resource, so the dict is
24+
the only source of the Traditional forms — and because it carries tokens
25+
(`Notes`, `Files`, `Tasks`, `Events`, object names) that no pack does. `en` and
26+
`zh` render byte-identically to before; the other eight locales change from the
27+
English token to their pack value. `page:accordion` reads the same lookup, so
28+
the two renderers cannot answer differently for one token.
29+
30+
Alongside it, the two `aria-label`s that were English in *every* locale —
31+
`HeaderHighlight`'s `Record highlights` and `RecordActivityTimeline`'s
32+
`Discussion` — now route through the bundle. Both sections carry no visible
33+
label, so the `aria-label` is the landmark as far as assistive tech is
34+
concerned (the argument objectui#4024 made for the dialog `Close` label, and
35+
objectui#5956 made for `record:path`'s own container name). `detail.discussion`
36+
already existed in all ten packs; `detail.highlightsLabel` is the single new
37+
key, added to all ten and mirrored byte-identically into
38+
`DETAIL_DEFAULT_TRANSLATIONS`.
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
* The built-in record-detail tab labels announce themselves in the session
11+
* locale — objectui#4645.
12+
*
13+
* `buildDefaultPageSchema` synthesizes the record-detail tab strip with plain
14+
* ENGLISH tokens on the nodes (`label: 'Details'`, `'Related'`,
15+
* `'Attachments'`, `'Activity'`, `'History'`, `'Approvals'`), and three of its
16+
* own comments say those tokens "localize through the tab strip's
17+
* KNOWN_LABEL_DICT". That dict shipped exactly two arms — `zh-CN` and `zh-TW`
18+
* — so the claim held for Chinese and silently failed for the eight other
19+
* shipped packs: a ja-JP / es-ES record detail rendered `Details / Related /
20+
* Attachments` inside otherwise fully-localized chrome.
21+
*
22+
* The packs already carry every one of these strings (`detail.details`,
23+
* `detail.related`, `detail.activity`, `detail.history`,
24+
* `detail.attachments`, `detail.approvalsPanelTitle` — all ten locales, no key
25+
* added by this change). The gap was purely that the tab strip never asked
26+
* them. It does now, BEHIND the exact-locale dict so `zh-TW` keeps the
27+
* Traditional forms it is the only source of.
28+
*
29+
* ── Direction of these assertions ─────────────────────────────────────────
30+
* `en` and `zh` were GREEN before this change and stay green — they pin that
31+
* routing through the packs did not move what an English or a Simplified
32+
* Chinese session reads (the dict's zh rows and the pack's zh rows are
33+
* byte-identical for these six tokens). The other eight packs were RED: every
34+
* one of them rendered the English token. `ja` and `es` are the two the card
35+
* measured in a real browser on 17.0.0 GA.
36+
*/
37+
38+
import { describe, it, expect, afterEach } from 'vitest';
39+
import { render, cleanup } from '@testing-library/react';
40+
import { I18nProvider, builtInLocales } from '@object-ui/i18n';
41+
import { SchemaRenderer } from '@object-ui/react';
42+
// Registers the renderers at module scope, NOT inside a `beforeAll` — there the
43+
// cold transform is billed to `hookTimeout`. See
44+
// object-ui/no-dynamic-import-in-test-hook (objectui#3010/#3021).
45+
import '../renderers';
46+
47+
/** Exactly the tokens `buildDefaultPageSchema` writes onto its tab nodes. */
48+
const SYNTHESIZED_TABS: Array<{ token: string; packKey: keyof typeof builtInLocales.en.detail }> = [
49+
{ token: 'Details', packKey: 'details' },
50+
{ token: 'Related', packKey: 'related' },
51+
{ token: 'Attachments', packKey: 'attachments' },
52+
{ token: 'Activity', packKey: 'activity' },
53+
{ token: 'History', packKey: 'history' },
54+
{ token: 'Approvals', packKey: 'approvalsPanelTitle' },
55+
];
56+
57+
const textChild = (content: string) => [{ type: 'element:text', properties: { content } }];
58+
59+
function renderSynthesizedStrip(language: string) {
60+
return render(
61+
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }}>
62+
<SchemaRenderer
63+
schema={{
64+
type: 'page:tabs',
65+
id: 'tabs',
66+
items: SYNTHESIZED_TABS.map(({ token }) => ({
67+
label: token,
68+
value: token.toLowerCase(),
69+
children: textChild(`${token} BODY`),
70+
})),
71+
}}
72+
/>
73+
</I18nProvider>,
74+
);
75+
}
76+
77+
const tabTexts = (container: HTMLElement) =>
78+
Array.from(container.querySelectorAll('[role="tab"]')).map((el) => el.textContent?.trim() ?? '');
79+
80+
afterEach(() => cleanup());
81+
82+
describe('page:tabs — built-in record-detail labels speak the session locale (objectui#4645)', () => {
83+
for (const language of Object.keys(builtInLocales) as Array<keyof typeof builtInLocales>) {
84+
it(`renders the ${language} pack values for every synthesized tab`, () => {
85+
const { container } = renderSynthesizedStrip(language);
86+
const pack = builtInLocales[language].detail as Record<string, string>;
87+
88+
expect(tabTexts(container)).toEqual(
89+
SYNTHESIZED_TABS.map(({ packKey }) => pack[packKey as string]),
90+
);
91+
});
92+
}
93+
94+
/**
95+
* The derived assertion above compares render output against the pack, so it
96+
* would pass vacuously for a pack whose values happened to BE the English
97+
* tokens. These two literals are the control: they are the exact strings the
98+
* card measured as missing in a real browser, written out rather than
99+
* derived.
100+
*/
101+
it('renders the ja-JP strings the card measured as English (lit control)', () => {
102+
const { container } = renderSynthesizedStrip('ja');
103+
const texts = tabTexts(container);
104+
105+
expect(texts).toContain('詳細');
106+
expect(texts).toContain('関連');
107+
expect(texts).toContain('添付ファイル');
108+
expect(texts).not.toContain('Details');
109+
expect(texts).not.toContain('Related');
110+
expect(texts).not.toContain('Attachments');
111+
});
112+
113+
it('renders the es-ES strings the card measured as English (lit control)', () => {
114+
const { container } = renderSynthesizedStrip('es');
115+
const texts = tabTexts(container);
116+
117+
expect(texts).toContain('Detalles');
118+
expect(texts).toContain('Relacionados');
119+
expect(texts).toContain('Adjuntos');
120+
expect(texts).not.toContain('Details');
121+
expect(texts).not.toContain('Related');
122+
expect(texts).not.toContain('Attachments');
123+
});
124+
125+
/**
126+
* `zh-TW` has no pack of its own — i18next resolves it to the Simplified
127+
* `zh` resource — so the exact-locale dict is the ONLY source of Traditional
128+
* forms for these tokens. It therefore stays AHEAD of the pack lookup, and
129+
* this is the assertion that says so.
130+
*/
131+
it('keeps the zh-TW Traditional forms the dict is the only source of', () => {
132+
const { container } = renderSynthesizedStrip('zh-TW');
133+
const texts = tabTexts(container);
134+
135+
expect(texts).toContain('詳情');
136+
expect(texts).toContain('相關');
137+
// The Simplified pack values, which a pack-first order would have produced.
138+
expect(texts).not.toContain('详情');
139+
expect(texts).not.toContain('相关');
140+
});
141+
142+
/**
143+
* An author-supplied label is not a well-known token and must survive
144+
* untouched — the strip localizes the synthesizer's English, never the
145+
* author's copy.
146+
*/
147+
it('leaves an authored label alone', () => {
148+
const { container } = render(
149+
<I18nProvider config={{ defaultLanguage: 'ja', detectBrowserLanguage: false }}>
150+
<SchemaRenderer
151+
schema={{
152+
type: 'page:tabs',
153+
id: 'tabs',
154+
items: [
155+
{ label: 'Invoices', value: 'a', children: textChild('A') },
156+
{ label: 'Details', value: 'b', children: textChild('B') },
157+
],
158+
}}
159+
/>
160+
</I18nProvider>,
161+
);
162+
163+
expect(tabTexts(container)).toEqual(['Invoices', '詳細']);
164+
});
165+
});

‎packages/components/src/renderers/layout/containers.tsx‎

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,31 @@ const labelText = (label: any): string => {
153153
};
154154

155155
/**
156-
* Lightweight built-in translation for well-known English tab/accordion
157-
* labels used by Lightning-style record pages (Details / Related /
158-
* Activity / History / Notes / Files / Tasks / Events / Attachments /
159-
* Chatter / Discussion). Keeps `@object-ui/components` free of an i18n
160-
* dependency while closing the gap between custom Page schemas (often
161-
* authored in English) and the localised default detail view.
156+
* EXACT-LOCALE overrides for well-known English tab/accordion labels used by
157+
* Lightning-style record pages (Details / Related / Activity / History /
158+
* Notes / Files / Tasks / Events / Attachments / Chatter / Discussion),
159+
* consulted AHEAD of `KNOWN_LABEL_KEYS` below.
160+
*
161+
* It shipped as the only source, with exactly two arms — and that was
162+
* objectui#4645: `buildDefaultPageSchema` writes plain English tokens onto the
163+
* synthesized record-detail tabs and three of its comments say they "localize
164+
* through the tab strip's KNOWN_LABEL_DICT", which was true for Chinese and
165+
* silently false for the eight other shipped packs. A ja-JP / es-ES record
166+
* detail rendered `Details / Related / Attachments` inside otherwise fully
167+
* localized chrome.
168+
*
169+
* What stays here is what the packs cannot answer:
170+
* - `zh-TW`. There is no `zh-TW` pack; i18next resolves it to the
171+
* SIMPLIFIED `zh` resource, so this map is the only source of the
172+
* Traditional forms. It must therefore win over the pack lookup, which is
173+
* why the dict is consulted first rather than second.
174+
* - the tokens no pack carries (`Notes`, `Files`, `Tasks`, `Events`,
175+
* `Overview`, and the object-name rows) — dropping them would take
176+
* coverage AWAY from zh.
162177
*
163178
* Authors can always override by passing a localised `label` (string or
164-
* `{ default, zh-CN, ... }` shape) directly in their schema; the map is
165-
* only consulted when the input matches a known English token.
179+
* `{ default, zh-CN, ... }` shape) directly in their schema; neither map is
180+
* consulted unless the input matches a known English token.
166181
*/
167182
const KNOWN_LABEL_DICT: Record<string, Record<string, string>> = {
168183
'zh-CN': {
@@ -229,6 +244,29 @@ const KNOWN_LABEL_DICT: Record<string, Record<string, string>> = {
229244
},
230245
};
231246

247+
/**
248+
* The other half of the same lookup: the well-known English tokens the ten
249+
* shipped packs ALREADY translate, mapped to the key that carries them
250+
* (objectui#4645). No pack key is minted here — every row below was in all ten
251+
* packs before this change; the tab strip simply never asked for them.
252+
*
253+
* These are exactly the tokens `buildDefaultPageSchema` writes onto its
254+
* synthesized tab nodes, plus the two `record:discussion` spellings, so the
255+
* built-in record detail is covered end to end. A token absent from this map
256+
* (an authored `Invoices` tab) is left alone, which is the contract the dict
257+
* already had.
258+
*/
259+
const KNOWN_LABEL_KEYS: Record<string, string> = {
260+
Details: 'detail.details',
261+
Related: 'detail.related',
262+
Activity: 'detail.activity',
263+
History: 'detail.history',
264+
Attachments: 'detail.attachments',
265+
Approvals: 'detail.approvalsPanelTitle',
266+
Discussion: 'detail.discussion',
267+
Comments: 'detail.comments',
268+
};
269+
232270
/**
233271
* `locale` is passed in rather than re-detected. Both call sites already
234272
* resolve it from `useObjectTranslation().language`; this function used to
@@ -238,26 +276,46 @@ const KNOWN_LABEL_DICT: Record<string, Record<string, string>> = {
238276
* in-app, because the DOM attribute and the i18n instance update
239277
* independently (objectui#2871).
240278
*/
241-
const translateLabel = (text: string, locale: string): string => {
279+
const translateLabel = (
280+
text: string,
281+
locale: string,
282+
tt: (keyOrKeys: string | string[], fallback: string) => string,
283+
): string => {
242284
if (!text) return text;
243285
// Match `zh-CN`, `zh-TW`, then base `zh` → `zh-CN`.
244286
const exact = KNOWN_LABEL_DICT[locale];
245287
const base = locale.split('-')[0];
246288
const fallback = base === 'zh' ? KNOWN_LABEL_DICT['zh-CN'] : undefined;
247289
const dict = exact || fallback;
248-
if (!dict) return text;
290+
/**
291+
* One token, in lookup order: the exact-locale dict, then the pack.
292+
*
293+
* `undefined` means "this token has no translation in this locale" — NOT
294+
* "the pack answered with the English token". `tt` falls back to its second
295+
* argument, so a pack miss and an `en` session both come back as `text`
296+
* itself; collapsing them here is what keeps the compound path below from
297+
* claiming a translation it does not have.
298+
*/
299+
const one = (token: string): string | undefined => {
300+
const hit = dict?.[token];
301+
if (hit !== undefined) return hit;
302+
const key = KNOWN_LABEL_KEYS[token];
303+
if (key === undefined) return undefined;
304+
const translated = tt(key, token);
305+
return translated === token ? undefined : translated;
306+
};
249307
// Direct hit on the full string.
250-
if (dict[text] !== undefined) return dict[text];
308+
const direct = one(text);
309+
if (direct !== undefined) return direct;
251310
// Try splitting on " & " / " 和 " / " and " separators so labels like
252311
// "Notes & Attachments" translate piece-wise to "备注 & 附件" without
253312
// requiring every concrete combination to be enumerated in the dict.
254313
const sepRe = /\s*(?:&|and|和)\s*/i;
255314
if (sepRe.test(text)) {
256-
const parts = text.split(sepRe);
257-
const allKnown = parts.every((p) => dict[p.trim()] !== undefined);
258-
if (allKnown) {
315+
const parts = text.split(sepRe).map((p) => p.trim()).map(one);
316+
if (parts.every((p) => p !== undefined)) {
259317
const sep = locale.startsWith('zh') ? '与' : ' & ';
260-
return parts.map((p) => dict[p.trim()]).join(sep);
318+
return (parts as string[]).join(sep);
261319
}
262320
}
263321
return text;
@@ -426,6 +484,11 @@ const PageTabsRenderer: React.FC<any> = ({ schema, className, ...props }) => {
426484
// `useObjectTranslation`), so the count-badge copy and the tab-label
427485
// localization below read the same session locale from one hook.
428486
const { t: tTabs, language } = useTabsTranslation();
487+
// The pack half of `translateLabel` (objectui#4645). Per-call rather than a
488+
// second defaults map: these keys carry no interpolation, and the English
489+
// token IS the fallback, so `useSafeTranslate`'s (keys, fallback) shape is
490+
// exactly the lookup.
491+
const ttLabel = useSafeTranslate();
429492
const rawItems: PageTabsItem[] = schema?.items || [];
430493
// Tab visual style lives at `properties.type` ('line'|'card'|'pill') — the
431494
// outer `schema.type` is always 'page:tabs' (the component dispatch key).
@@ -633,7 +696,7 @@ const PageTabsRenderer: React.FC<any> = ({ schema, className, ...props }) => {
633696
value: typeof (it as any).value === 'string' && (it as any).value !== '' ? (it as any).value : `tab-${idx}`,
634697
// pickLocalized first (honours `{ en, zh }` / `{ default }`); translateLabel
635698
// then maps any plain-English well-known token (Details/Related/…) to the locale.
636-
labelStr: translateLabel(pickLocalized(it.label, language), language),
699+
labelStr: translateLabel(pickLocalized(it.label, language), language, ttLabel),
637700
// Explicit spec count wins; otherwise fall back to the derived probe.
638701
count: it.count !== undefined && it.count !== null && it.count !== ''
639702
? it.count
@@ -880,6 +943,10 @@ interface PageAccordionItem {
880943
const PageAccordionRenderer: React.FC<any> = ({ schema, className, ...props }) => {
881944
const { designer } = splitDesignerProps(props);
882945
const { language } = useObjectTranslation();
946+
// Same lookup the tab strip reads (objectui#4645) — `page:accordion` is the
947+
// other renderer that localizes well-known English section labels, and the
948+
// two must not answer differently for the same token.
949+
const ttLabel = useSafeTranslate();
883950
const items: PageAccordionItem[] = schema?.items || [];
884951
const allowMultiple = !!schema?.allowMultiple;
885952
// Variants:
@@ -895,7 +962,7 @@ const PageAccordionRenderer: React.FC<any> = ({ schema, className, ...props }) =
895962
const itemsWithValue = items.map((it, idx) => ({
896963
...it,
897964
value: `panel-${idx}`,
898-
labelStr: translateLabel(pickLocalized(it.label, language), language),
965+
labelStr: translateLabel(pickLocalized(it.label, language), language, ttLabel),
899966
}));
900967

901968
const defaultOpen = itemsWithValue

‎packages/i18n/src/locales/ar.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ const ar = {
10741074
sortBy: "ترتيب حسب",
10751075
filterPlaceholder: "تصفية…",
10761076
highlightFields: "الحقول الرئيسية",
1077+
highlightsLabel: "الحقول الرئيسية للسجل",
10771078
createdBy: "أنشأه",
10781079
updatedBy: "حدّثه",
10791080
// objectui#3863 — base key, and in ar this is the slot users actually hit: `zero`,

‎packages/i18n/src/locales/de.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ const de = {
10681068
sortBy: "Sortieren nach",
10691069
filterPlaceholder: "Filtern…",
10701070
highlightFields: "Schlüsselfelder",
1071+
highlightsLabel: "Schlüsselfelder des Datensatzes",
10711072
createdBy: "Erstellt von",
10721073
updatedBy: "Aktualisiert von",
10731074
created: "Erstellt",

‎packages/i18n/src/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ const en = {
11141114
sortBy: 'Sort by',
11151115
filterPlaceholder: 'Filter…',
11161116
highlightFields: 'Key Fields',
1117+
highlightsLabel: 'Record highlights',
11171118
// Comments
11181119
comments: 'Comments',
11191120
searchComments: 'Search comments…',

0 commit comments

Comments
 (0)