Skip to content

Commit db9b349

Browse files
committed
test(i18n): read the marketplace namespace's catalogues by table tag
The marketplace shape, lazy-load and console gate suites name the zh-Hans / zh-Hant / pt-BR catalogues and packs; a stored zh-TW reader is pinned to the Traditional catalogue; the freshness suite holds every zh-Hant target the generator writes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibyWSiXh6B2sMVHfXYC
1 parent 248747d commit db9b349

5 files changed

Lines changed: 104 additions & 52 deletions

File tree

‎ui/packages/app-shell/src/console/marketplace/__tests__/MarketplacePage.namespaceGate-30588.test.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,24 @@ import { NotificationBanners } from '@object-ui/components';
9494
import { builtInLocales } from '@object-ui/i18n/locales';
9595
import { BUILT_IN_LANGUAGE_CODES, registerBuiltInLocale } from '@object-ui/i18n/locales/registry';
9696
import en from '@object-ui/i18n/locales/en';
97-
import zh from '@object-ui/i18n/locales/zh';
97+
import zhHans from '@object-ui/i18n/locales/zh-Hans';
98+
import zhHant from '@object-ui/i18n/locales/zh-Hant';
9899
import ja from '@object-ui/i18n/locales/ja';
99100
import ko from '@object-ui/i18n/locales/ko';
100101
import de from '@object-ui/i18n/locales/de';
101102
import fr from '@object-ui/i18n/locales/fr';
102103
import es from '@object-ui/i18n/locales/es';
103-
import pt from '@object-ui/i18n/locales/pt';
104+
import ptBr from '@object-ui/i18n/locales/pt-BR';
104105
import ru from '@object-ui/i18n/locales/ru';
105106
import ar from '@object-ui/i18n/locales/ar';
106107
import { initRuntimeConfig, resetRuntimeConfigForTesting } from '../../../runtime-config';
107108
import { MarketplacePage } from '../MarketplacePage';
108109
import { MarketplacePackagePage } from '../MarketplacePackagePage';
109110
import { rememberSampleData, resetSampleDataSessionForTesting } from '../sampleDataNotice';
110111

111-
const PACKS: Record<string, Record<string, unknown>> = { en, zh, ja, ko, de, fr, es, pt, ru, ar };
112+
const PACKS: Record<string, Record<string, unknown>> = {
113+
en, 'zh-Hans': zhHans, 'zh-Hant': zhHant, ja, ko, de, fr, es, 'pt-BR': ptBr, ru, ar,
114+
};
112115
for (const code of BUILT_IN_LANGUAGE_CODES) registerBuiltInLocale(code, PACKS[code]);
113116

114117
const ENGLISH = builtInLocales.en.marketplace;
@@ -177,7 +180,7 @@ function renderRecording(page: ReactElement, language: string) {
177180

178181
describe('the marketplace pages wait for their strings (objectstack#30588)', () => {
179182
it('zh-CN: the catalogue page shows the load skeleton, then Chinese, and never English or a raw key', async () => {
180-
const zhMarketplace = builtInLocales.zh.marketplace;
183+
const zhMarketplace = builtInLocales['zh-Hans'].marketplace;
181184
const view = renderRecording(<MarketplacePage />, 'zh-CN');
182185
// The first frame holds no namespace text yet — in no language, and not
183186
// as a key — only the skeleton.
@@ -252,7 +255,7 @@ describe('the marketplace pages wait for their strings (objectstack#30588)', ()
252255
}
253256

254257
const view = renderRecording(<Console />, 'zh-CN');
255-
expect((await screen.findAllByText(builtInLocales.zh.marketplace.back)).length).toBeGreaterThan(0);
258+
expect((await screen.findAllByText(builtInLocales['zh-Hans'].marketplace.back)).length).toBeGreaterThan(0);
256259

257260
// The switch sends the frame back to its skeleton until the Japanese
258261
// catalogue lands, which unmounts the page body. That is not a leave.
@@ -261,7 +264,7 @@ describe('the marketplace pages wait for their strings (objectstack#30588)', ()
261264
});
262265
expect((await screen.findAllByText(builtInLocales.ja.marketplace.back)).length).toBeGreaterThan(0);
263266
const beforeLeaving = (await view.shown()).join('\n');
264-
for (const pack of [builtInLocales.en, builtInLocales.zh, builtInLocales.ja]) expect(beforeLeaving).not.toContain(banner(pack));
267+
for (const pack of [builtInLocales.en, builtInLocales['zh-Hans'], builtInLocales.ja]) expect(beforeLeaving).not.toContain(banner(pack));
265268

266269
// Leaving the page is: the banner follows, in the console's language.
267270
await act(async () => {

‎ui/packages/i18n/src/__tests__/marketplace-namespace-lazy.test.tsx‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* The DOM setup (`vitest.setup.i18n-catalogues.ts`) calls
2020
* `registerBuiltInLocales()`, which registers every language COMPLETE —
2121
* namespace included — so a page would never need a fetch, which is the
22-
* all-ten door's promise and not what a console visitor gets. This file
22+
* all-packs door's promise and not what a console visitor gets. This file
2323
* re-registers each language as its pack ALONE, at module scope: the registry
2424
* a console that awaited `preloadBootstrapLocale()` holds. A `dom` project
2525
* isolates each file's module graph, so nothing here reaches another file,
@@ -32,17 +32,19 @@ import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
3232
import { I18nProvider, useI18nContext, useObjectTranslation } from '../provider.js';
3333
import { BUILT_IN_LANGUAGE_CODES, registerBuiltInLocale } from '../locales/registry.js';
3434
import enPack from '../locales/en.js';
35-
import zhPack from '../locales/zh.js';
35+
import zhHansPack from '../locales/zh-Hans.js';
36+
import zhHantPack from '../locales/zh-Hant.js';
3637
import jaPack from '../locales/ja.js';
3738
import koPack from '../locales/ko.js';
3839
import dePack from '../locales/de.js';
3940
import frPack from '../locales/fr.js';
4041
import esPack from '../locales/es.js';
41-
import ptPack from '../locales/pt.js';
42+
import ptBrPack from '../locales/pt-BR.js';
4243
import ruPack from '../locales/ru.js';
4344
import arPack from '../locales/ar.js';
4445
import enNs from '../namespaces/marketplace/en.js';
45-
import zhNs from '../namespaces/marketplace/zh.js';
46+
import zhNs from '../namespaces/marketplace/zh-Hans.js';
47+
import zhHantNs from '../namespaces/marketplace/zh-Hant.js';
4648
import jaNs from '../namespaces/marketplace/ja.js';
4749
import {
4850
isMarketplaceCatalogueLoaded,
@@ -58,8 +60,8 @@ vi.mock('../namespaces/marketplace/ko.js', async (importOriginal) => {
5860
});
5961

6062
const PACKS: Record<string, Record<string, unknown>> = {
61-
en: enPack, zh: zhPack, ja: jaPack, ko: koPack, de: dePack,
62-
fr: frPack, es: esPack, pt: ptPack, ru: ruPack, ar: arPack,
63+
en: enPack, 'zh-Hans': zhHansPack, 'zh-Hant': zhHantPack, ja: jaPack, ko: koPack, de: dePack,
64+
fr: frPack, es: esPack, 'pt-BR': ptBrPack, ru: ruPack, ar: arPack,
6365
};
6466
for (const code of BUILT_IN_LANGUAGE_CODES) registerBuiltInLocale(code, PACKS[code]);
6567

@@ -114,7 +116,7 @@ const EN_TITLE = enNs.marketplace.title;
114116

115117
describe('marketplace namespace — lazy', () => {
116118
it('a Chinese page waits, then renders Chinese from its first render', async () => {
117-
expect(isMarketplaceCatalogueLoaded('zh')).toBe(false);
119+
expect(isMarketplaceCatalogueLoaded('zh-Hans')).toBe(false);
118120
expect(isMarketplaceCatalogueLoaded('en')).toBe(false);
119121

120122
renderIn('zh-CN');
@@ -128,9 +130,21 @@ describe('marketplace namespace — lazy', () => {
128130
expect(seen.length).toBeGreaterThan(0);
129131
expect(seen.filter((entry) => entry !== `zh-CN|${ZH_TITLE}`)).toEqual([]);
130132
// What it fetched: its own catalogue and the fallback, nothing else.
131-
expect(isMarketplaceCatalogueLoaded('zh')).toBe(true);
133+
expect(isMarketplaceCatalogueLoaded('zh-Hans')).toBe(true);
132134
expect(isMarketplaceCatalogueLoaded('en')).toBe(true);
133135
expect(isMarketplaceCatalogueLoaded('ja')).toBe(false);
136+
expect(isMarketplaceCatalogueLoaded('zh-Hant')).toBe(false);
137+
});
138+
139+
it('a Traditional Chinese reader (a stored zh-TW) gets the zh-Hant catalogue, not the Simplified one', async () => {
140+
renderIn('zh-TW');
141+
const title = zhHantNs.marketplace.title;
142+
// Lit control: the two catalogues really differ on the probe key.
143+
expect(title).not.toBe(ZH_TITLE);
144+
expect(await screen.findByText(title)).toBeTruthy();
145+
expect(screen.getByTestId('refresh').textContent).toBe(zhHantNs.marketplace.refresh);
146+
expect(seen.filter((entry) => entry !== `zh-TW|${title}`)).toEqual([]);
147+
expect(isMarketplaceCatalogueLoaded('zh-Hant')).toBe(true);
134148
});
135149

136150
it('a language switch waits again for the new language', async () => {

‎ui/packages/i18n/src/__tests__/marketplace-namespace.test.ts‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/**
22
* The `marketplace` namespace (objectstack#30588): its shape, and how it sits
3-
* beside the ten packs it was cut out of.
3+
* beside the packs it was cut out of: one catalogue per platform locale table
4+
* tag (objectstack#30511), keyed by the tag as the packs are.
45
*
5-
* 1. LAZY BY CONSTRUCTION. `namespaces/marketplace/index.ts` reaches its ten
6-
* catalogues through ten literal `import()`s and nothing else — no static
6+
* 1. LAZY BY CONSTRUCTION. `namespaces/marketplace/index.ts` reaches its
7+
* catalogues through one literal `import()` each and nothing else — no static
78
* import, no template-literal specifier — so each is a chunk of its own
89
* and none is in the console's first load.
910
* 2. CUT, NOT COPIED. Every catalogue holds only the `marketplace` group and
1011
* the probe key the page frame waits on; no pack holds the probe key, and
1112
* no leaf is in both a pack and its catalogue.
12-
* 3. THE ALL-TEN DOOR IS COMPLETE. `locales/index.ts` hands out each language
13+
* 3. THE ALL-PACKS DOOR IS COMPLETE. `locales/index.ts` hands out each language
1314
* as its pack merged with its catalogue, so the parity suites that walk
1415
* `builtInLocales` still walk these keys; the package entry's `en` is the
1516
* resident pack alone.
@@ -30,23 +31,25 @@ import { en as entryEn } from '../index.js';
3031
import { BUILT_IN_LANGUAGE_CODES } from '../locales/registry.js';
3132
import { builtInLocales } from '../locales/index.js';
3233
import enPack from '../locales/en.js';
33-
import zhPack from '../locales/zh.js';
34+
import zhHansPack from '../locales/zh-Hans.js';
35+
import zhHantPack from '../locales/zh-Hant.js';
3436
import jaPack from '../locales/ja.js';
3537
import koPack from '../locales/ko.js';
3638
import dePack from '../locales/de.js';
3739
import frPack from '../locales/fr.js';
3840
import esPack from '../locales/es.js';
39-
import ptPack from '../locales/pt.js';
41+
import ptBrPack from '../locales/pt-BR.js';
4042
import ruPack from '../locales/ru.js';
4143
import arPack from '../locales/ar.js';
4244
import enNs from '../namespaces/marketplace/en.js';
43-
import zhNs from '../namespaces/marketplace/zh.js';
45+
import zhHansNs from '../namespaces/marketplace/zh-Hans.js';
46+
import zhHantNs from '../namespaces/marketplace/zh-Hant.js';
4447
import jaNs from '../namespaces/marketplace/ja.js';
4548
import koNs from '../namespaces/marketplace/ko.js';
4649
import deNs from '../namespaces/marketplace/de.js';
4750
import frNs from '../namespaces/marketplace/fr.js';
4851
import esNs from '../namespaces/marketplace/es.js';
49-
import ptNs from '../namespaces/marketplace/pt.js';
52+
import ptBrNs from '../namespaces/marketplace/pt-BR.js';
5053
import ruNs from '../namespaces/marketplace/ru.js';
5154
import arNs from '../namespaces/marketplace/ar.js';
5255
import {
@@ -63,12 +66,12 @@ const INDEX_PATH = join(HERE, '..', 'namespaces', 'marketplace', 'index.ts');
6366

6467
type Tree = Record<string, unknown>;
6568
const PACKS: Record<string, Tree> = {
66-
en: enPack, zh: zhPack, ja: jaPack, ko: koPack, de: dePack,
67-
fr: frPack, es: esPack, pt: ptPack, ru: ruPack, ar: arPack,
69+
en: enPack, 'zh-Hans': zhHansPack, 'zh-Hant': zhHantPack, ja: jaPack, ko: koPack, de: dePack,
70+
fr: frPack, es: esPack, 'pt-BR': ptBrPack, ru: ruPack, ar: arPack,
6871
};
6972
const CATALOGUES: Record<string, Tree> = {
70-
en: enNs, zh: zhNs, ja: jaNs, ko: koNs, de: deNs,
71-
fr: frNs, es: esNs, pt: ptNs, ru: ruNs, ar: arNs,
73+
en: enNs, 'zh-Hans': zhHansNs, 'zh-Hant': zhHantNs, ja: jaNs, ko: koNs, de: deNs,
74+
fr: frNs, es: esNs, 'pt-BR': ptBrNs, ru: ruNs, ar: arNs,
7275
};
7376

7477
function leaves(node: unknown, prefix = ''): string[] {
@@ -109,12 +112,14 @@ describe('marketplace namespace — lazy by construction', () => {
109112
});
110113

111114
it('statically imports no catalogue (nothing of it rides in with the page frame)', () => {
112-
expect(staticSpecifiers.filter((s) => /^\.\/[a-z]{2}\.js$/.test(s))).toEqual([]);
115+
// A catalogue specifier is `./<tag>.js`: a language, or a language and a
116+
// script or region subtag (`./zh-Hant.js`, `./pt-BR.js`).
117+
expect(staticSpecifiers.filter((s) => /^\.\/[a-z]{2}(?:-[A-Za-z]+)?\.js$/.test(s))).toEqual([]);
113118
// Lit control: the static imports were read.
114119
expect(staticSpecifiers).toContain('../../locales/registry.js');
115120
});
116121

117-
it('ships the ten built-in languages', () => {
122+
it('ships one catalogue per built-in language (the platform locale table)', () => {
118123
expect([...MARKETPLACE_LANGUAGE_CODES].sort()).toEqual([...BUILT_IN_LANGUAGE_CODES].sort());
119124
});
120125
});
@@ -139,7 +144,7 @@ describe('marketplace namespace — cut out of the packs, not copied', () => {
139144
});
140145
});
141146

142-
describe('marketplace namespace — the all-ten door hands out complete languages', () => {
147+
describe('marketplace namespace — the all-packs door hands out complete languages', () => {
143148
it.each(BUILT_IN_LANGUAGE_CODES.map((code) => [code]))('%s: pack keys and namespace keys are both there', (code) => {
144149
const complete = (builtInLocales as unknown as Record<string, Tree>)[code];
145150
const expected = [...leaves(PACKS[code]), ...leaves(CATALOGUES[code])].sort();
@@ -157,10 +162,14 @@ describe('marketplace namespace — the all-ten door hands out complete language
157162

158163
describe('marketplace namespace — language resolution and the loader', () => {
159164
it.each([
160-
['zh-CN', 'zh'],
161-
['zh', 'zh'],
162-
['zh-TW', 'zh'],
163-
['pt-BR', 'pt'],
165+
['zh-CN', 'zh-Hans'],
166+
['zh', 'zh-Hans'],
167+
['zh-Hans', 'zh-Hans'],
168+
['zh-TW', 'zh-Hant'],
169+
['zh-HK', 'zh-Hant'],
170+
['zh-Hant', 'zh-Hant'],
171+
['pt', 'pt-BR'],
172+
['pt-BR', 'pt-BR'],
164173
['ar-EG', 'ar'],
165174
['en-US', 'en'],
166175
['de', 'de'],

‎ui/packages/i18n/src/__tests__/zh-hant-generated.test.ts‎

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
22

33
/**
4-
* The committed zh-Hant pack is exactly what the generator writes from the
5-
* committed zh-Hans pack (objectstack#30511, ruling F of objectstack#29349).
4+
* Every committed zh-Hant catalogue is exactly what the generator writes from
5+
* its committed zh-Hans source (objectstack#30511, ruling F of
6+
* objectstack#29349): the pack, and each pack-shaped lazy namespace's
7+
* catalogue (`ZH_HANT_TARGETS`).
68
*
7-
* `src/locales/zh-Hant.ts` is not hand-written: `scripts/gen-zh-hant.mjs`
8-
* converts `src/locales/zh-Hans.ts` with the rules in `scripts/zh-hant.mjs`
9-
* (OpenCC `s2twp`, pinned, plus the www.objectos.ai overrides). Two edits can
10-
* leave the pair out of step, and both are ordinary edits that read as done:
9+
* `src/locales/zh-Hant.ts` and `src/namespaces/marketplace/zh-Hant.ts` are not
10+
* hand-written: `scripts/gen-zh-hant.mjs` converts their `zh-Hans.ts` sources
11+
* with the rules in `scripts/zh-hant.mjs` (OpenCC `s2twp`, pinned, plus the
12+
* www.objectos.ai overrides). Two edits can leave a pair out of step, and both
13+
* are ordinary edits that read as done:
1114
*
1215
* - a zh-Hans string changed and `gen:zh-hant` was not run, so Traditional
1316
* readers keep the retired sentence;
1417
* - a conversion rule changed and the pack was not regenerated, so the rule
1518
* says one word and the pack shows another.
1619
*
1720
* Either one reds here, with the command that repairs it. ⛔ The repair is
18-
* never a hand edit of `zh-Hant.ts`: the next regeneration would undo it.
21+
* never a hand edit of a `zh-Hant.ts`: the next regeneration would undo it.
1922
* A rendering that is wrong belongs in `TWP_PHRASE_OVERRIDES` (and in the
2023
* site's converter, which the rules are copied from).
2124
*
@@ -31,33 +34,56 @@ import {
3134
CONVERSION_CASES,
3235
GATE_ONLY_KEYS,
3336
GENERATED_HEADER,
37+
NAMESPACE_GENERATED_HEADER,
38+
ZH_HANT_TARGETS,
3439
conversionFailures,
35-
generateZhHantPack,
3640
s2t,
3741
} from '../../scripts/zh-hant.mjs';
3842
import zhHans from '../locales/zh-Hans.js';
3943
import zhHant from '../locales/zh-Hant.js';
44+
import zhHansMarketplace from '../namespaces/marketplace/zh-Hans.js';
45+
import zhHantMarketplace from '../namespaces/marketplace/zh-Hant.js';
4046

4147
// Rooted on THIS FILE, never on `process.cwd()`: the package-scoped and the
4248
// repo-root vitest invocations run in different directories (AGENTS.md).
4349
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
4450
const read = (relative: string) => readFileSync(path.join(packageRoot, relative), 'utf8');
4551

46-
const REGENERATE = 'run `pnpm --filter @object-ui/i18n gen:zh-hant` and commit src/locales/zh-Hant.ts';
52+
const regenerate = (target: string) =>
53+
`run \`pnpm --filter @object-ui/i18n gen:zh-hant\` and commit ${target}`;
4754

48-
describe('the zh-Hant pack is generated, and current', () => {
49-
it('is byte-for-byte what the generator writes from zh-Hans.ts', () => {
50-
const committed = read('src/locales/zh-Hant.ts');
51-
const generated = generateZhHantPack(read('src/locales/zh-Hans.ts'));
52-
// A boolean first, so a stale pack fails with the repair rather than with
53-
// a 5,000-line diff; the equality below is what a reviewer then reads.
54-
expect(committed === generated, `zh-Hant.ts is stale: ${REGENERATE}`).toBe(true);
55-
expect(committed).toBe(generated);
55+
describe('every zh-Hant catalogue is generated, and current', () => {
56+
it('generates the pack and the marketplace namespace catalogue', () => {
57+
// Counter-probe: an emptied target list would make the cases below vacuous.
58+
expect(ZH_HANT_TARGETS.map(({ target }) => target)).toEqual([
59+
'src/locales/zh-Hant.ts',
60+
'src/namespaces/marketplace/zh-Hant.ts',
61+
]);
5662
});
5763

58-
it('opens with the generated marker, so nobody edits it by hand', () => {
64+
it.each(ZH_HANT_TARGETS.map((entry) => [entry.target, entry]))(
65+
'%s is byte-for-byte what the generator writes from its zh-Hans source',
66+
(target, { source, generate }) => {
67+
const committed = read(target);
68+
const generated = generate(read(source));
69+
// A boolean first, so a stale catalogue fails with the repair rather than
70+
// with a 5,000-line diff; the equality below is what a reviewer then reads.
71+
expect(committed === generated, `${target} is stale: ${regenerate(target)}`).toBe(true);
72+
expect(committed).toBe(generated);
73+
},
74+
);
75+
76+
it('each opens with the generated marker, so nobody edits it by hand', () => {
5977
expect(read('src/locales/zh-Hant.ts').startsWith(GENERATED_HEADER)).toBe(true);
78+
expect(read('src/namespaces/marketplace/zh-Hant.ts').startsWith(NAMESPACE_GENERATED_HEADER)).toBe(true);
6079
expect(GENERATED_HEADER).toContain('@generated');
80+
expect(NAMESPACE_GENERATED_HEADER).toContain('@generated');
81+
});
82+
83+
it('converts the namespace catalogue rather than copying it', () => {
84+
expect(zhHansMarketplace.marketplace.refresh).toBe('刷新');
85+
expect(zhHantMarketplace.marketplace.refresh).toBe(s2t(zhHansMarketplace.marketplace.refresh));
86+
expect(zhHantMarketplace.marketplace.refresh).not.toBe(zhHansMarketplace.marketplace.refresh);
6187
});
6288

6389
it('answers every pinned conversion case', () => {

‎ui/scripts/__tests__/check-i18n-en-drift.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ describe('a language is its pack plus its namespace partial packs', () => {
530530
Object.fromEntries(LOCALES.map((lang) => [`${NS}${lang}.ts`, packSource(lang, trees[lang])]));
531531

532532
it('names one partial pack per language per namespace', () => {
533-
expect(namespacePackPaths('zh')).toEqual(['packages/i18n/src/namespaces/marketplace/zh.ts']);
533+
expect(namespacePackPaths('zh-Hans')).toEqual(['packages/i18n/src/namespaces/marketplace/zh-Hans.ts']);
534534
});
535535

536536
it('a group MOVED from the pack to its namespace is no drift and no key-set change', () => {

0 commit comments

Comments
 (0)