-
Notifications
You must be signed in to change notification settings - Fork 16
/
po2json.cjs
29 lines (27 loc) · 944 Bytes
/
po2json.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* eslint-disable require-jsdoc */
const fs = require('fs');
const path = require('path');
const parser = require('ttag-cli/dist/src/lib/parser');
const utils = require('ttag-cli/dist/src/lib/utils');
for (const arg of process.argv.slice(2)) {
const outpath = './src/' + path.basename(arg) + '.ts';
console.log(`${arg} => ${outpath}`);
writePoFile(arg, outpath, false);
}
function writePoFile(inpath, outpath, nostrip) {
const poData = parser.parse(
fs.readFileSync(inpath).toString().normalize(),
);
const messages = utils.iterateTranslations(poData.translations);
if (!nostrip) {
const header = messages.next().value;
delete header.comments;
for (const msg of messages) {
delete msg.comments;
}
}
const outstream = fs.createWriteStream(outpath, {flags: 'w'});
outstream.write('export default ');
outstream.write(JSON.stringify(utils.convert2Compact(poData), null, 0));
outstream.end();
}