Files
descrybe/apps/web/scripts/list-missing.mjs
T

33 lines
1.3 KiB
JavaScript
Raw Normal View History

import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { createRequire } from "node:module";
// Re-parse PACKS by evaluating gen script is hard; instead diff en vs es.
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const messagesDir = path.resolve(__dirname, "../src/lib/i18n/messages");
function parseMessageDict(source) {
const dict = {};
const re = /"([^"\\]+)"\s*:\s*((?:"(?:\\.|[^"\\])*")|(?:`(?:\\.|[^`\\])*`))/gs;
let m;
while ((m = re.exec(source))) {
const key = m[1];
const raw = m[2];
dict[key] = raw.startsWith("`")
? raw.slice(1, -1).replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\n/g, "\n")
: JSON.parse(raw);
}
return dict;
}
const en = parseMessageDict(fs.readFileSync(path.join(messagesDir, "en.ts"), "utf8"));
const es = parseMessageDict(fs.readFileSync(path.join(messagesDir, "es.ts"), "utf8"));
const missing = {};
for (const [k, v] of Object.entries(en)) {
if (es[k] === v) missing[k] = v; // likely untranslated (same as en) OR intentionally same
}
// Prefer keys not in our known translated set — dump all where es === en
fs.writeFileSync(path.join(__dirname, "_missing.json"), JSON.stringify(missing, null, 2), "utf8");
console.log(`candidates same-as-en: ${Object.keys(missing).length}`);