mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 01:46:38 +02:00
📎 Minor improvements to translations scripts.
This commit is contained in:
parent
5a49ce2028
commit
bb719d6211
5 changed files with 52 additions and 170 deletions
31
frontend/scripts/validate-translations.js
Normal file
31
frontend/scripts/validate-translations.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
const fs = require('fs').promises;
|
||||
const gt = require("gettext-parser");
|
||||
const l = require("lodash");
|
||||
const path = require('path');
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
;(async () => {
|
||||
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);
|
||||
const data = gt.po.parse(content, "utf-8")
|
||||
const buff = gt.po.compile(data, {sort: true});
|
||||
await fs.writeFile(f, buff);
|
||||
}
|
||||
})()
|
Loading…
Add table
Add a link
Reference in a new issue