-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathi18n_json2csv.js
More file actions
42 lines (36 loc) · 987 Bytes
/
Copy pathi18n_json2csv.js
File metadata and controls
42 lines (36 loc) · 987 Bytes
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
39
40
41
42
const localelist = ['en', 'pt', 'ja', 'vi', 'es', 'hi', 'ms', 'zh', 'th', 'id'];
const tree = localelist.reduce((pre, cur) => {
const locale = require(`./${cur}.json`);
Object.keys(locale).forEach((key) => {
if (pre[key]) {
pre[key][cur] = locale[key];
} else {
if (!['es', 'it', 'fr'].includes(cur)) {
pre[key] = {
[cur]: locale[key],
};
}
}
});
return pre;
}, {});
const data = Object.keys(tree).map((key) => {
// if (Object.keys(tree[key]).length > 0) {
// return {
// keys: key,
// ...tree[key],
// };
// }
const larr = localelist.map((lang) => {
return tree[key][lang] || null;
});
larr.unshift(key);
return larr;
});
data.unshift(['keys'].concat(localelist));
console.log(data);
const xlsx = require('node-xlsx').default;
const fs = require('fs');
const ws = fs.createWriteStream('out.xlsx');
var buffer = xlsx.build([{name: "mySheetName", data: data}]);
ws.write(buffer);