Replace po2json with pofile

The former doesn't seem to be properly maintained and nodejs gives
deprecation warnings.
This commit is contained in:
Pierre Ossman 2024-12-17 17:13:30 +01:00
parent 3e2e04bea1
commit 673cb349fd
2 changed files with 9 additions and 10 deletions

View File

@ -56,7 +56,7 @@
"karma-safari-launcher": "latest", "karma-safari-launcher": "latest",
"karma-script-launcher": "latest", "karma-script-launcher": "latest",
"mocha": "latest", "mocha": "latest",
"po2json": "latest", "pofile": "latest",
"sinon": "latest", "sinon": "latest",
"sinon-chai": "latest" "sinon-chai": "latest"
}, },

View File

@ -19,22 +19,21 @@
const { program } = require('commander'); const { program } = require('commander');
const fs = require('fs'); const fs = require('fs');
const po2json = require("po2json"); const pofile = require("pofile");
program program
.argument('<input>') .argument('<input>')
.argument('<output>') .argument('<output>')
.parse(process.argv); .parse(process.argv);
const data = po2json.parseFileSync(program.args[0]); let data = fs.readFileSync(program.args[0], "utf8");
let po = pofile.parse(data);
const bodyPart = Object.keys(data) const bodyPart = po.items
.filter(msgid => msgid !== "") .filter(item => item.msgid !== "")
.filter(msgid => data[msgid][1] !== "") .filter(item => item.msgstr[0] !== "")
.map((msgid) => { .map(item => " " + JSON.stringify(item.msgid) + ": " + JSON.stringify(item.msgstr[0]))
const msgstr = data[msgid][1]; .join(",\n");
return " " + JSON.stringify(msgid) + ": " + JSON.stringify(msgstr);
}).join(",\n");
const output = "{\n" + bodyPart + "\n}"; const output = "{\n" + bodyPart + "\n}";