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-script-launcher": "latest",
"mocha": "latest",
"po2json": "latest",
"pofile": "latest",
"sinon": "latest",
"sinon-chai": "latest"
},

View File

@ -19,22 +19,21 @@
const { program } = require('commander');
const fs = require('fs');
const po2json = require("po2json");
const pofile = require("pofile");
program
.argument('<input>')
.argument('<output>')
.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)
.filter(msgid => msgid !== "")
.filter(msgid => data[msgid][1] !== "")
.map((msgid) => {
const msgstr = data[msgid][1];
return " " + JSON.stringify(msgid) + ": " + JSON.stringify(msgstr);
}).join(",\n");
const bodyPart = po.items
.filter(item => item.msgid !== "")
.filter(item => item.msgstr[0] !== "")
.map(item => " " + JSON.stringify(item.msgid) + ": " + JSON.stringify(item.msgstr[0]))
.join(",\n");
const output = "{\n" + bodyPart + "\n}";