-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlocale.js
60 lines (49 loc) · 1.29 KB
/
locale.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const request = require('request');
const fs = require('fs')
console.log('Generate locale');
main();
function main() {
let = langRes = {};
getFolder('./Localization/src/Extension').forEach(el => {
const tLang = readFile('./Localization/src/Extension/'+el);
langRes = {...langRes, ...tLang};
});
getFolder('./Localization/src/Presence').forEach(el => {
const tLang = readFile('./Localization/src/Presence/'+el);
langRes = {...langRes, ...tLang};
});
writeObj(langRes);
}
function getFolder(path) {
return fs.readdirSync(path);
}
function readFile(path) {
const data = fs.readFileSync(path, 'utf8');
const json = JSON.parse(data);
const res = {};
for (const el in json) {
res[el] = json[el].message;
}
return res;
}
function writeObj(obj) {
console.log(obj);
const content = `
var language = ${JSON.stringify(obj)};
`;
fs.writeFileSync('./Extension/Pages/locale.js', content);
}
async function getJson(url) {
return new Promise((resolve, reject) => {
request({url: url}, function (error, response, body) {
if(error) {
console.error('error:', error);
reject(error);
return;
}
if(response && response.statusCode === 200) {
resolve(JSON.parse(body));
}
});
})
}