|
1 | 1 | import { createHash } from "node:crypto"; |
2 | 2 | import { existsSync, readFileSync } from "node:fs"; |
3 | | -import { readFile, stat } from "node:fs/promises"; |
4 | | -import { pathToFileURL } from "node:url"; |
| 3 | +import { readFile } from "node:fs/promises"; |
| 4 | +import path from "node:path"; |
| 5 | +import { fileURLToPath } from "node:url"; |
| 6 | +import { registerActivityEnglish } from "../../ui/src/i18n/locales/en-activity.ts"; |
| 7 | +import { registerPluginConsentEnglish } from "../../ui/src/i18n/locales/en-plugin-consent.ts"; |
| 8 | +import { registerSessionPlacementEnglish } from "../../ui/src/i18n/locales/en-session-placement.ts"; |
| 9 | +import { registerSettingsEnglish } from "../../ui/src/i18n/locales/en-settings.ts"; |
| 10 | +import { en } from "../../ui/src/i18n/locales/en.ts"; |
5 | 11 | import type { TranslationMap, TranslationMemoryEntry } from "./control-ui-i18n-sync-plan.ts"; |
6 | 12 |
|
7 | | -async function importControlUiLocaleModule<T>(filePath: string): Promise<T> { |
8 | | - const stats = await stat(filePath); |
9 | | - return (await import(`${pathToFileURL(filePath).href}?ts=${stats.mtimeMs}`)) as T; |
10 | | -} |
| 13 | +// Host-only owner for generation, verification and Vite. Static imports let Vite |
| 14 | +// track every English dependency (including en.ts's en-agents.ts import). |
| 15 | +const localesDir = path.resolve( |
| 16 | + path.dirname(fileURLToPath(import.meta.url)), |
| 17 | + "../../ui/src/i18n/locales", |
| 18 | +); |
| 19 | +const sourceFiles = [ |
| 20 | + "en.ts", |
| 21 | + "en-agents.ts", |
| 22 | + "en-activity.ts", |
| 23 | + "en-session-placement.ts", |
| 24 | + "en-plugin-consent.ts", |
| 25 | + "en-settings.ts", |
| 26 | +]; |
11 | 27 |
|
12 | | -export async function loadControlUiLocaleCatalog( |
13 | | - filePath: string, |
14 | | - exportName: string, |
15 | | -): Promise<TranslationMap | null> { |
16 | | - if (!existsSync(filePath)) { |
17 | | - return null; |
18 | | - } |
19 | | - const module = await importControlUiLocaleModule<Record<string, TranslationMap>>(filePath); |
20 | | - return module[exportName] ?? null; |
21 | | -} |
22 | | - |
23 | | -export async function loadControlUiSourceCatalog( |
24 | | - sourceLocalePath: string, |
25 | | - activitySourceLocalePath: string, |
26 | | - sessionPlacementSourceLocalePath: string, |
27 | | - pluginConsentSourceLocalePath: string, |
28 | | -): Promise<TranslationMap> { |
29 | | - const source = await loadControlUiLocaleCatalog(sourceLocalePath, "en"); |
30 | | - const activitySource = ( |
31 | | - await importControlUiLocaleModule<{ |
32 | | - registerActivityEnglish: { catalog: TranslationMap }; |
33 | | - }>(activitySourceLocalePath) |
34 | | - ).registerActivityEnglish.catalog; |
35 | | - const sessionPlacementSource = ( |
36 | | - await importControlUiLocaleModule<{ |
37 | | - registerSessionPlacementEnglish: { catalog: TranslationMap }; |
38 | | - }>(sessionPlacementSourceLocalePath) |
39 | | - ).registerSessionPlacementEnglish.catalog; |
40 | | - const pluginConsentSource = ( |
41 | | - await importControlUiLocaleModule<{ |
42 | | - registerPluginConsentEnglish: { catalog: TranslationMap }; |
43 | | - }>(pluginConsentSourceLocalePath) |
44 | | - ).registerPluginConsentEnglish.catalog; |
45 | | - if (!source || !activitySource || !sessionPlacementSource || !pluginConsentSource) { |
46 | | - throw new Error("Control UI English source catalogs are incomplete"); |
47 | | - } |
| 28 | +export function loadControlUiSourceCatalog(): TranslationMap { |
| 29 | + // Read fragment data without registering it into the shared runtime catalog. |
| 30 | + // en.ts's empty anchors retain source order for extracted whole subtrees. |
48 | 31 | return mergeControlUiTranslationMaps( |
49 | | - source, |
50 | | - activitySource, |
51 | | - sessionPlacementSource, |
52 | | - pluginConsentSource, |
| 32 | + en, |
| 33 | + registerActivityEnglish.catalog, |
| 34 | + registerSessionPlacementEnglish.catalog, |
| 35 | + registerPluginConsentEnglish.catalog, |
| 36 | + registerSettingsEnglish.catalog, |
53 | 37 | ); |
54 | 38 | } |
55 | 39 |
|
56 | | -export async function readControlUiSourceCatalog( |
57 | | - sourceLocalePath: string, |
58 | | - activitySourceLocalePath: string, |
59 | | - sessionPlacementSourceLocalePath: string, |
60 | | - pluginConsentSourceLocalePath: string, |
61 | | -): Promise<string> { |
| 40 | +export async function readControlUiSourceCatalog(): Promise<string> { |
62 | 41 | const sources = await Promise.all( |
63 | | - [ |
64 | | - sourceLocalePath, |
65 | | - activitySourceLocalePath, |
66 | | - sessionPlacementSourceLocalePath, |
67 | | - pluginConsentSourceLocalePath, |
68 | | - ].map((filePath) => readFile(filePath, "utf8")), |
| 42 | + sourceFiles.map((fileName) => readFile(path.join(localesDir, fileName), "utf8")), |
69 | 43 | ); |
70 | 44 | return sources.join("\n"); |
71 | 45 | } |
|
0 commit comments