2022-02-15 17:45:26 +01:00
|
|
|
import { potextract } from "./potextract.js";
|
2022-02-16 16:31:36 +01:00
|
|
|
import * as child_process from "child_process";
|
|
|
|
import * as fs from "fs";
|
|
|
|
import glob = require("glob");
|
|
|
|
import { po2ts } from "./po2ts.js";
|
2022-02-15 17:45:26 +01:00
|
|
|
|
|
|
|
function usage(): never {
|
|
|
|
console.log("usage: pogen <extract|merge|emit>");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
const subcommand = process.argv[2];
|
|
|
|
if (process.argv.includes("--help") || !subcommand) {
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
switch (subcommand) {
|
|
|
|
case "extract":
|
|
|
|
potextract();
|
|
|
|
break;
|
2022-02-16 16:31:36 +01:00
|
|
|
case "merge": {
|
|
|
|
const packageJson = JSON.parse(
|
|
|
|
fs.readFileSync("./package.json", { encoding: "utf-8" }),
|
|
|
|
);
|
|
|
|
|
|
|
|
const poDomain = packageJson.pogen?.domain;
|
|
|
|
if (!poDomain) {
|
|
|
|
console.error("missing 'pogen.domain' field in package.json");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
const files = glob.sync("src/i18n/*.po");
|
|
|
|
console.log(files);
|
|
|
|
for (const f of files) {
|
|
|
|
console.log(`merging ${f}`);
|
|
|
|
child_process.execSync(
|
|
|
|
`msgmerge -o '${f}' '${f}' 'src/i18n/${poDomain}.pot'`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "emit":
|
|
|
|
po2ts();
|
|
|
|
break;
|
2022-02-15 17:45:26 +01:00
|
|
|
default:
|
|
|
|
console.error(`unknown subcommand '${subcommand}'`);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|