-
Notifications
You must be signed in to change notification settings - Fork 661
/
Copy pathformat_lang.js
58 lines (49 loc) · 1.34 KB
/
format_lang.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
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
const fs = require('fs');
const f = (key, value, plural) => {
value = value
.replace(/\n/g, '\\n')
.replace(/"/g, '\\"');
return `"${key}${plural ? '_' + plural.replace('_value', '') : ''}" = "${value}";\n`;
};
let out = '';
['lang', 'langSign'].forEach(part => {
const path = `../${part}.ts`;
let str = fs.readFileSync(path).toString()
.replace(/\s+\/\/.+/g, '')
// .replace(/\\'/g, '')
.replace(/"/g, `\\"`)
// .replace(/'/g, '"')
.replace(/([^\\])'/g, '$1"')
.replace(/\\'/g, '\'')
// .replace(/"(.+?)(?:")(.*?)"/g, '"$1\"$2"');
{
const pattern = '= {';
str = str.slice(str.indexOf(pattern) + pattern.length - 1);
}
{
const pattern = '};';
str = str.slice(0, str.indexOf(pattern) + pattern.length - 1);
}
// console.log(`'${str}'`);
// var idx = 21865;
// idx -= 1;
// console.log(str.slice(idx, idx + 100));
const json = JSON.parse(str);
console.log(json);
for(const key in json) {
const value = json[key];
if(typeof(value) === 'string') {
out += f(key, value);
} else {
for(const plural in value) {
out += f(key, value[plural], plural);
}
}
}
});
fs.writeFileSync('./out/langPack.strings', out);