Skip to content

Commit 69ab56e

Browse files
committed
feat(i18n): the marketplace pages fetch their strings as a lazy namespace before they render
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgXDwFw71MwSG9FKYDQ
1 parent 1992c59 commit 69ab56e

11 files changed

Lines changed: 656 additions & 89 deletions

File tree

‎ui/apps/console/vite.config.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,26 @@ export default defineConfig({
12351235
{ name: 'i18n-ns-studio-en', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]en\.ts$/, priority: 84 },
12361236
{ name: 'i18n-ns-studio-zh', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]studio[\\/]zh\.ts$/, priority: 84 },
12371237
//
1238+
// The `marketplace` namespace (objectstack#30588): the pack group the
1239+
// two marketplace pages read, moved out of the ten packs so the
1240+
// eager `i18n-locale-en` chunk stops carrying it. All ten catalogues
1241+
// are `import()`ed by `packages/i18n/src/namespaces/marketplace/index.ts`
1242+
// when a marketplace page mounts, none is resident, so one group per
1243+
// catalogue for the rule above. The loader module gets a group too:
1244+
// without one it would fall to `i18n-runtime` below and be eager,
1245+
// while its only reader is the marketplace pages' lazy route chunk.
1246+
{ name: 'i18n-ns-marketplace', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]index\.ts$/, priority: 84 },
1247+
{ name: 'i18n-ns-marketplace-en', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]en\.ts$/, priority: 84 },
1248+
{ name: 'i18n-ns-marketplace-zh', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]zh\.ts$/, priority: 84 },
1249+
{ name: 'i18n-ns-marketplace-ja', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]ja\.ts$/, priority: 84 },
1250+
{ name: 'i18n-ns-marketplace-ko', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]ko\.ts$/, priority: 84 },
1251+
{ name: 'i18n-ns-marketplace-de', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]de\.ts$/, priority: 84 },
1252+
{ name: 'i18n-ns-marketplace-fr', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]fr\.ts$/, priority: 84 },
1253+
{ name: 'i18n-ns-marketplace-es', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]es\.ts$/, priority: 84 },
1254+
{ name: 'i18n-ns-marketplace-pt', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]pt\.ts$/, priority: 84 },
1255+
{ name: 'i18n-ns-marketplace-ru', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]ru\.ts$/, priority: 84 },
1256+
{ name: 'i18n-ns-marketplace-ar', test: /[\\/]packages[\\/]i18n[\\/]src[\\/]namespaces[\\/]marketplace[\\/]ar\.ts$/, priority: 84 },
1257+
//
12381258
// ⛔ `i18n-runtime` takes `includeDependenciesRecursively: false`
12391259
// for the reason `data-adapter` below does (objectui#9345, read out
12401260
// there in full): it outranks `framework` (83 over 80), and since
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The marketplace pages' frame for their own strings (objectstack#30588).
5+
*
6+
* The `marketplace.*` keys these pages read are not in the console's eager
7+
* language pack: they are `@object-ui/i18n`'s lazy `marketplace` namespace,
8+
* fetched when a page here mounts (the namespace module's header says why).
9+
* This frame renders the page only once the namespace answers `ready` for the
10+
* instance's language, so a visitor sees the copy-free load skeleton the pages
11+
* already use (`MarketplaceResolving`), never an English sentence in a
12+
* translated console nor a raw key. A language switch while a page is open
13+
* shows the skeleton again until that language's catalogue has arrived.
14+
*
15+
* A catalogue that cannot be fetched is said once, in the console's own error
16+
* words (resident pack keys, which need no fetch), with a Try again that asks
17+
* for it again — never a skeleton that waits forever, and never a retry loop.
18+
*
19+
* ⛔ Every component in this directory that reads a `marketplace.*` key renders
20+
* under this frame: the two pages wrap their bodies in it. The two families a
21+
* page outside this route reads (`marketplace.install.dependencyMissing`,
22+
* `marketplace.install.protocolCheckSkipped`) stayed in the packs for that
23+
* reason, so `dependencyMissing.ts` and `protocolCheckSkipped.ts` need no frame.
24+
*/
25+
26+
import type { ReactNode } from 'react';
27+
import { RotateCcw } from 'lucide-react';
28+
import { Button, Empty, EmptyTitle } from '@object-ui/components';
29+
import { useObjectTranslation } from '@object-ui/i18n';
30+
import { useMarketplaceNamespace } from '@object-ui/i18n/namespaces/marketplace';
31+
import { MarketplaceResolving } from './MarketplaceResolving.js';
32+
33+
export function MarketplaceNamespaceGate({ children }: { children: ReactNode }) {
34+
const namespace = useMarketplaceNamespace();
35+
if (namespace.status === 'ready') return <>{children}</>;
36+
if (namespace.status === 'failed') return <MarketplaceNamespaceFailed onRetry={namespace.retry} />;
37+
return <MarketplaceResolving />;
38+
}
39+
40+
function MarketplaceNamespaceFailed({ onRetry }: { onRetry: () => void }) {
41+
const { t } = useObjectTranslation();
42+
return (
43+
<div
44+
className="mx-auto flex w-full max-w-6xl items-center justify-center p-8"
45+
data-testid="marketplace-namespace-failed"
46+
>
47+
<Empty>
48+
<EmptyTitle>{t('console.errors.somethingWentWrong')}</EmptyTitle>
49+
<Button variant="outline" size="sm" onClick={onRetry} className="mt-4 gap-2">
50+
<RotateCcw className="h-4 w-4" />
51+
{t('console.errors.tryAgain')}
52+
</Button>
53+
</Empty>
54+
</div>
55+
);
56+
}

‎ui/packages/app-shell/src/console/marketplace/MarketplacePackagePage.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import { SuggestedBindingsPanel, type SuggestedBindingsStrings } from '../../com
103103
import { ConnectorCredentialsStep } from './ConnectorCredentialsStep.js';
104104
import type { SuggestedBinding } from '../../services/suggestedBindingsApi.js';
105105
import { errorCodeIs } from '@object-ui/types';
106+
import { MarketplaceNamespaceGate } from './MarketplaceNamespaceGate.js';
106107

107108
/**
108109
* Whether a cloud install lands in the environment this console renders, read
@@ -154,7 +155,19 @@ function versionEntryId(version: string): string {
154155
return `marketplace-version-${version}`;
155156
}
156157

158+
/**
159+
* The page under the frame that fetches its strings first — the
160+
* `marketplace` namespace (`MarketplaceNamespaceGate.tsx` says why).
161+
*/
157162
export function MarketplacePackagePage() {
163+
return (
164+
<MarketplaceNamespaceGate>
165+
<MarketplacePackagePageBody />
166+
</MarketplaceNamespaceGate>
167+
);
168+
}
169+
170+
function MarketplacePackagePageBody() {
158171
const navigate = useNavigate();
159172
const { packageId, appName } = useParams<{ packageId?: string; appName?: string }>();
160173
const { isAdmin, isResolved } = useWorkspaceAdminStatus();

‎ui/packages/app-shell/src/console/marketplace/MarketplacePage.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { useProtocolCheckSkippedText } from './protocolCheckSkipped.js';
5656
import { ProtocolCheckSkippedNote } from './ProtocolCheckSkippedNote.js';
5757
import { ConnectorCredentialsStep } from './ConnectorCredentialsStep.js';
5858
import { packagesHref } from '../../views/metadata-admin/packageSource.js';
59+
import { MarketplaceNamespaceGate } from './MarketplaceNamespaceGate.js';
5960

6061
/**
6162
* The card grid's track (objectui#12616): a card is never narrower than 240px,
@@ -306,7 +307,19 @@ type OrgDeployState =
306307
| { phase: 'served'; manifestId: string; version: string | undefined; name: string; app: ServedApp | null }
307308
| { phase: 'timeout'; manifestId: string; version: string | undefined; name: string };
308309

310+
/**
311+
* The page under the frame that fetches its strings first — the
312+
* `marketplace` namespace (`MarketplaceNamespaceGate.tsx` says why).
313+
*/
309314
export function MarketplacePage() {
315+
return (
316+
<MarketplaceNamespaceGate>
317+
<MarketplacePageBody />
318+
</MarketplaceNamespaceGate>
319+
);
320+
}
321+
322+
function MarketplacePageBody() {
310323
const navigate = useNavigate();
311324
const { appName } = useParams();
312325
const { isAdmin, isResolved } = useWorkspaceAdminStatus();

‎ui/packages/i18n/README.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,36 @@ and retired `check:i18n-designer-parity`, which paired the two homes. App-shell'
421421
still skips app-shell's translator **by declaration** (its `EXCLUDED_TRANSLATORS`
422422
entry), so a second local table cannot appear silently.
423423

424+
## The `marketplace` namespace — the marketplace pages' strings, fetched with them
425+
426+
The `marketplace.*` keys are ordinary pack keys to their readers — app-shell's
427+
marketplace pages ask `t('marketplace.…')` like any other component — but they
428+
are not in the packs. They live in
429+
[`src/namespaces/marketplace/`](./src/namespaces/marketplace/index.ts), reached
430+
through the `@object-ui/i18n/namespaces/marketplace` subpath:
431+
432+
- **Ten catalogues, all lazy.** `src/namespaces/marketplace/<code>.ts` is a
433+
partial pack — the same shape as `src/locales/<code>.ts`, holding only the
434+
`marketplace` group. Each is its own chunk; none is in the console's first
435+
load, so the eager `en` pack does not carry two lazy pages' text.
436+
- **A page waits for them.** `useMarketplaceNamespace()` fetches the catalogue
437+
for the instance's language plus `en` (the packs' fallback) and deep-merges
438+
them into the instance, never over a host's own `resources`. App-shell's
439+
marketplace pages render a copy-free loading frame until it answers `ready`,
440+
and again after a language switch, so a visitor never reads English in a
441+
translated page nor a raw key.
442+
- **Two families stay in the packs.** `marketplace.install.dependencyMissing`
443+
and `marketplace.install.protocolCheckSkipped` are read by Studio's packages
444+
page too, outside the marketplace route, so they stay resident.
445+
- **Inside the pack gates.** `@object-ui/i18n/locales` hands out each language
446+
COMPLETE — its pack merged with its namespace catalogue — so key parity and
447+
every suite that walks `builtInLocales` still walk these keys, and
448+
`registerBuiltInLocales()` makes them resident with the rest. The call-site,
449+
dead-key and `en`-drift gates under `ui/scripts/` read the namespace files as
450+
part of the packs and refuse a key defined in both.
451+
452+
The package entry's `en` is the resident pack alone, without the namespace.
453+
424454
## Links
425455

426456
- 📦 [npm package](https://www.npmjs.com/package/@object-ui/i18n)

‎ui/packages/i18n/package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
"types": "./dist/namespaces/studio/index.d.ts",
3838
"import": "./dist/namespaces/studio/index.js",
3939
"default": "./dist/namespaces/studio/index.js"
40+
},
41+
"./namespaces/marketplace": {
42+
"types": "./dist/namespaces/marketplace/index.d.ts",
43+
"import": "./dist/namespaces/marketplace/index.js",
44+
"default": "./dist/namespaces/marketplace/index.js"
4045
}
4146
},
4247
"scripts": {

‎ui/packages/i18n/src/locales/index.ts‎

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,91 @@
1616
* that says what it costs.
1717
*
1818
* ⚠️ Anything on a page-load path belongs on `./registry.js`, not here.
19+
*
20+
* ## Each catalogue here is COMPLETE: the pack plus its lazy namespaces
21+
*
22+
* Some of a language's strings are not in its pack: the `marketplace.*` group
23+
* is a lazy namespace (`../namespaces/marketplace/`), fetched when a
24+
* marketplace page mounts so the console's eager `en` pack does not carry it.
25+
* This door's two purposes both want every string, so each language it hands
26+
* out is its pack deep-merged with its catalogue from every such namespace:
27+
* the parity / drift suites keep walking the moved keys, and an app that makes
28+
* every catalogue resident gets the marketplace text resident too. A key in
29+
* both places is refused at module evaluation — the gates refuse it as well.
30+
*
31+
* ⚠️ So `en` here is not the same object as the package entry's `en`, which is
32+
* the RESIDENT pack alone (what an instance holds before any namespace has
33+
* loaded), nor as `@object-ui/i18n/locales/en`, the pack module itself.
1934
*/
20-
export { default as en, type TranslationKeys } from './en.js';
21-
export { default as zh } from './zh.js';
22-
export { default as ja } from './ja.js';
23-
export { default as ko } from './ko.js';
24-
export { default as de } from './de.js';
25-
export { default as fr } from './fr.js';
26-
export { default as es } from './es.js';
27-
export { default as pt } from './pt.js';
28-
export { default as ru } from './ru.js';
29-
export { default as ar } from './ar.js';
35+
import enPack from './en.js';
36+
import zhPack from './zh.js';
37+
import jaPack from './ja.js';
38+
import koPack from './ko.js';
39+
import dePack from './de.js';
40+
import frPack from './fr.js';
41+
import esPack from './es.js';
42+
import ptPack from './pt.js';
43+
import ruPack from './ru.js';
44+
import arPack from './ar.js';
45+
import enMarketplace from '../namespaces/marketplace/en.js';
46+
import zhMarketplace from '../namespaces/marketplace/zh.js';
47+
import jaMarketplace from '../namespaces/marketplace/ja.js';
48+
import koMarketplace from '../namespaces/marketplace/ko.js';
49+
import deMarketplace from '../namespaces/marketplace/de.js';
50+
import frMarketplace from '../namespaces/marketplace/fr.js';
51+
import esMarketplace from '../namespaces/marketplace/es.js';
52+
import ptMarketplace from '../namespaces/marketplace/pt.js';
53+
import ruMarketplace from '../namespaces/marketplace/ru.js';
54+
import arMarketplace from '../namespaces/marketplace/ar.js';
55+
56+
export type { TranslationKeys } from './en.js';
57+
58+
const isPlainObject = (value: unknown): value is Record<string, unknown> =>
59+
typeof value === 'object' && value !== null && !Array.isArray(value);
3060

3161
/**
32-
* Map of all built-in locales keyed by language code
62+
* `pack` deep-merged with a namespace's partial pack. Groups both sides hold
63+
* (`marketplace`, `marketplace.install`) merge; a LEAF both sides hold is a
64+
* key defined twice, which no reader could resolve the same way twice, and
65+
* throws.
3366
*/
34-
import en from './en.js';
35-
import zh from './zh.js';
36-
import ja from './ja.js';
37-
import ko from './ko.js';
38-
import de from './de.js';
39-
import fr from './fr.js';
40-
import es from './es.js';
41-
import pt from './pt.js';
42-
import ru from './ru.js';
43-
import ar from './ar.js';
67+
function complete<P extends object, N extends object>(pack: P, partial: N, label: string): P & N {
68+
const merge = (into: Record<string, unknown>, from: Record<string, unknown>, at: string) => {
69+
const out: Record<string, unknown> = { ...into };
70+
for (const key of Object.keys(from)) {
71+
if (key === '__proto__') continue;
72+
const path = at ? `${at}.${key}` : key;
73+
if (isPlainObject(out[key]) && isPlainObject(from[key])) {
74+
out[key] = merge(out[key] as Record<string, unknown>, from[key] as Record<string, unknown>, path);
75+
} else if (Object.prototype.hasOwnProperty.call(out, key)) {
76+
throw new Error(`${label}: \`${path}\` is defined both in the pack and in a namespace catalogue.`);
77+
} else {
78+
out[key] = from[key];
79+
}
80+
}
81+
return out;
82+
};
83+
return merge(pack as Record<string, unknown>, partial as Record<string, unknown>, '') as P & N;
84+
}
85+
86+
// Annotated rather than inferred: the inferred type spells the packs' literal
87+
// types out inline in the emitted declaration, which outgrew what tsc will
88+
// serialize (TS7056). Each `typeof` is emitted as a reference.
89+
export const en: typeof enPack & typeof enMarketplace = complete(enPack, enMarketplace, 'en');
90+
export const zh: typeof zhPack & typeof zhMarketplace = complete(zhPack, zhMarketplace, 'zh');
91+
export const ja: typeof jaPack & typeof jaMarketplace = complete(jaPack, jaMarketplace, 'ja');
92+
export const ko: typeof koPack & typeof koMarketplace = complete(koPack, koMarketplace, 'ko');
93+
export const de: typeof dePack & typeof deMarketplace = complete(dePack, deMarketplace, 'de');
94+
export const fr: typeof frPack & typeof frMarketplace = complete(frPack, frMarketplace, 'fr');
95+
export const es: typeof esPack & typeof esMarketplace = complete(esPack, esMarketplace, 'es');
96+
export const pt: typeof ptPack & typeof ptMarketplace = complete(ptPack, ptMarketplace, 'pt');
97+
export const ru: typeof ruPack & typeof ruMarketplace = complete(ruPack, ruMarketplace, 'ru');
98+
export const ar: typeof arPack & typeof arMarketplace = complete(arPack, arMarketplace, 'ar');
4499

45-
// Annotated rather than inferred: the inferred type spells all ten packs'
46-
// literal types out inline in the emitted declaration, which outgrew what tsc
47-
// will serialize (TS7056). Each `typeof <pack>` is the same type, emitted as a
48-
// reference.
100+
/**
101+
* Map of all built-in locales keyed by language code — each one complete (see
102+
* the header).
103+
*/
49104
export const builtInLocales: {
50105
readonly en: typeof en;
51106
readonly zh: typeof zh;

0 commit comments

Comments
 (0)