From 465ccdaa06d30a995235fd6438172eb125243321 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 15 Feb 2022 17:45:26 +0100 Subject: subcommands for i18n tooling, unique message IDs --- packages/pogen/src/po2ts.ts | 62 +++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'packages/pogen/src/po2ts.ts') diff --git a/packages/pogen/src/po2ts.ts b/packages/pogen/src/po2ts.ts index d0f4ed34d..ac85b9b76 100644 --- a/packages/pogen/src/po2ts.ts +++ b/packages/pogen/src/po2ts.ts @@ -23,38 +23,44 @@ import * as po2json from "po2json"; import * as fs from "fs"; import * as path from "path"; -const files = fs - .readdirSync("./src/i18n") - .filter((x) => x.endsWith(".po")) - .map((x) => path.join("./src/i18n/", x)); - -if (files.length === 0) { - console.error("no .po files found in src/i18n/"); - process.exit(1); -} +export function po2ts(): void { + const files = fs + .readdirSync("./src/i18n") + .filter((x) => x.endsWith(".po")) + .map((x) => path.join("./src/i18n/", x)); -console.log(files); + if (files.length === 0) { + console.error("no .po files found in src/i18n/"); + process.exit(1); + } -const chunks: string[] = []; + console.log(files); -for (const filename of files) { - const m = filename.match(/([a-zA-Z0-9-_]+).po/); + const chunks: string[] = []; - if (!m) { - console.error("error: unexpected filename (expected .po)"); - process.exit(1); - } + for (const filename of files) { + const m = filename.match(/([a-zA-Z0-9-_]+).po/); - const lang = m[1]; - const pojson = po2json.parseFileSync(filename, { - format: "jed1.x", - fuzzy: true, - }); - const s = - "strings['" + lang + "'] = " + JSON.stringify(pojson, null, " ") + ";\n\n"; - chunks.push(s); -} + if (!m) { + console.error("error: unexpected filename (expected .po)"); + process.exit(1); + } + + const lang = m[1]; + const pojson = po2json.parseFileSync(filename, { + format: "jed1.x", + fuzzy: true, + }); + const s = + "strings['" + + lang + + "'] = " + + JSON.stringify(pojson, null, " ") + + ";\n\n"; + chunks.push(s); + } -const tsContents = chunks.join(""); + const tsContents = chunks.join(""); -fs.writeFileSync("src/i18n/strings.ts", tsContents); + fs.writeFileSync("src/i18n/strings.ts", tsContents); +} -- cgit v1.2.3