@@ -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 */
167182const 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 * (?: & | a n d | 和 ) \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 {
880943const 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
0 commit comments