2024-07-01 03:28:40 -05:00
|
|
|
import { promises as fs } from "fs";
|
|
|
|
import gt from "gettext-parser";
|
|
|
|
import l from "lodash";
|
|
|
|
import path from "path";
|
2021-04-14 08:43:17 -05:00
|
|
|
|
|
|
|
async function* getFiles(dir) {
|
|
|
|
const dirents = await fs.readdir(dir, { withFileTypes: true });
|
|
|
|
for (const dirent of dirents) {
|
|
|
|
const res = path.resolve(dir, dirent.name);
|
|
|
|
if (dirent.isDirectory()) {
|
|
|
|
yield* getFiles(res);
|
|
|
|
} else {
|
|
|
|
yield res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-01 03:28:40 -05:00
|
|
|
(async () => {
|
2021-04-14 08:43:17 -05:00
|
|
|
const fileRe = /.+\.po$/;
|
|
|
|
const target = path.normalize("./translations/");
|
|
|
|
const parent = path.join(target, "..");
|
|
|
|
for await (const f of getFiles(target)) {
|
|
|
|
if (!fileRe.test(f)) continue;
|
|
|
|
const entry = path.relative(parent, f);
|
|
|
|
console.log(`=> processing: ${entry}`);
|
|
|
|
const content = await fs.readFile(f);
|
2024-07-01 03:28:40 -05:00
|
|
|
const data = gt.po.parse(content, "utf-8");
|
|
|
|
const buff = gt.po.compile(data, { sort: true });
|
2021-04-14 08:43:17 -05:00
|
|
|
await fs.writeFile(f, buff);
|
|
|
|
}
|
2024-07-01 03:28:40 -05:00
|
|
|
})();
|