GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — onicode/scripts/i18n-check.ts at main · aislopware/onicode

Expand file tree

/

i18n-check.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
86 lines (79 loc) · 3.85 KB
/

i18n-check.ts

Copy path

File metadata and controls

86 lines (79 loc) · 3.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
// @effect-diagnostics nodeBuiltinImport:off globalConsole:off - A one-shot CI check; synchronous Node APIs keep it small.
// Fails when a committed GT catalog drifts from the source: `gt generate` would write a different
// en.json, or a locale catalog's keys differ from en.json. Needs no GT credentials or network.
import * as NodeChildProcess from "node:child_process";
import * as NodeFS from "node:fs";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";
// Desktop only depends on gt-i18n, so the gt CLI hides `generate` there; its script adds it back.
// The gt CLI runs through Node because the `.bin/gt` shim is a shell script Windows cannot spawn.
const GENERATE: Record<string, readonly [string, ...string[]]> = {
"apps/web": [process.execPath, "node_modules/gt/bin/main.js", "generate"],
"apps/mobile": [process.execPath, "node_modules/gt/bin/main.js", "generate"],
"apps/desktop": [process.execPath, "scripts/i18n-generate.mjs"],
};
const APPS = Object.keys(GENERATE);
// JSX entries (`<T>`) are arrays and objects, so values compare by their JSON text.
type Catalog = Record<string, unknown>;
const readJson = (file: string) => JSON.parse(NodeFS.readFileSync(file, "utf8"));
const missingFrom = (from: Catalog, catalog: Catalog) =>
Object.keys(from).filter((key) => !Object.hasOwn(catalog, key));
const root = NodePath.resolve(import.meta.dirname, "..");
const problems: string[] = [];
for (const [app, [command, ...args]] of Object.entries(GENERATE)) {
const appDir = NodePath.join(root, app);
const config = readJson(NodePath.join(appDir, "gt.config.json"));
const catalogDir = NodePath.join(appDir, NodePath.dirname(config.files.gt.output));
const source: Catalog = readJson(NodePath.join(catalogDir, `${config.defaultLocale}.json`));
// Same scan as `vp run i18n:generate`, but it writes only the source catalog, to a temp dir.
const tmp = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "i18n-check-"));
try {
const tmpConfig = NodePath.join(tmp, "gt.config.json");
NodeFS.writeFileSync(
tmpConfig,
JSON.stringify({ ...config, locales: [], files: { gt: { output: `${tmp}/[locale].json` } } }),
);
const gt = NodeChildProcess.spawnSync(command, [...args, "--config", tmpConfig], {
cwd: appDir,
encoding: "utf8",
});
if (gt.status !== 0) {
problems.push(`${app}: gt generate failed\n${gt.stdout}${gt.stderr}`);
continue;
}
const generated: Catalog = readJson(NodePath.join(tmp, `${config.defaultLocale}.json`));
for (const [key, text] of Object.entries(generated)) {
if (!Object.hasOwn(source, key)) {
problems.push(`${app}: ${key} ${JSON.stringify(text)} is missing from en.json`);
} else if (JSON.stringify(source[key]) !== JSON.stringify(text)) {
problems.push(
`${app}: en.json has ${key} ${JSON.stringify(source[key])}, source says ${JSON.stringify(text)}`,
);
}
}
for (const key of missingFrom(source, generated)) {
problems.push(`${app}: ${key} ${JSON.stringify(source[key])} in en.json is stale`);
}
} finally {
NodeFS.rmSync(tmp, { recursive: true, force: true });
}
for (const locale of config.locales) {
const catalog: Catalog = readJson(NodePath.join(catalogDir, `${locale}.json`));
for (const key of missingFrom(source, catalog)) {
problems.push(`${app}: ${locale}.json is missing ${key} ${JSON.stringify(source[key])}`);
}
for (const key of missingFrom(catalog, source)) {
problems.push(`${app}: ${locale}.json has ${key}, which en.json lacks`);
}
}
}
if (problems.length > 0) {
console.error(problems.join("\n"));
console.error(
"\nRun `vp run i18n:generate` in the app, then translate any new keys in every locale catalog.",
);
process.exitCode = 1;
} else {
console.log(`i18n catalogs match the source in ${APPS.join(", ")}.`);
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.