-
Notifications
You must be signed in to change notification settings - Fork 1
/
po2json.js
38 lines (32 loc) · 1.06 KB
/
po2json.js
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
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
const process = require('process');
const PO = require('pofile');
if (process.argv.length === 3) {
PO.load(process.argv[2], (err, po) => {
if (!err) {
const messages = {
"": {
domain: po.headers['X-Domain'] || 'messages',
lang: po.headers.Language,
plural_forms: po.headers['Plural-Forms'],
},
};
po.items.forEach((item) => {
const key = item.msgctxt !== null ? `${item.msgctxt}\u0004${item.msgid}` : item.msgid;
messages[key] = item.msgstr;
});
const result = {
domain: po.headers['X-Domain'] || 'messages',
locale_data: {
messages,
}
}
process.stdout.write(JSON.stringify(result));
process.exit(0);
}
process.stderr.write(err.toString());
process.exit(1);
});
} else {
process.stderr.write('Usage: po2json input.po\n');
}