import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const enPath = path.resolve(__dirname, "../src/lib/i18n/messages/en.ts"); const outPath = path.resolve(__dirname, "_en-dump.json"); 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(enPath, "utf8")); fs.writeFileSync(outPath, JSON.stringify(en, null, 2), "utf8"); console.log(`keys=${Object.keys(en).length} -> ${outPath}`);