-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgettext.js-po-loader.js
33 lines (26 loc) · 977 Bytes
/
gettext.js-po-loader.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
/**
* Copyright (c) 2023 WebCimes - RICHARD Florian (https://webcimes.com)
* MIT License - https://choosealicense.com/licenses/mit/
* Date: 2023-04-27
*
* Based on po2json wrapper from Guillaume Potier (https://github.com/guillaumepotier/gettext.js/blob/master/bin/po2json)
*/
const po2json = require('po2json');
module.exports = function(source) {
let jsonData = po2json.parse(source);
let json = {};
for (var key in jsonData) {
// Special headers handling, we do not need everything
if ('' === key) {
json[''] = {
'language': jsonData['']['language'],
'plural-forms': jsonData['']['plural-forms']
};
continue;
}
// Do not dump untranslated keys, they already are in the templates!
if ('' !== jsonData[key][1])
json[key] = 2 === jsonData[key].length ? jsonData[key][1] : jsonData[key].slice(1);
}
return JSON.stringify(json);
}