2021-04-08 13:52:31 +00:00
|
|
|
/*
|
|
|
|
* https://github.com/morethanwords/tweb
|
|
|
|
* Copyright (C) 2019-2021 Eduard Kuzmenko
|
|
|
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
2021-03-24 17:45:38 +00:00
|
|
|
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 = '';
|
2021-04-04 18:46:09 +00:00
|
|
|
|
|
|
|
['lang', 'langSign'].forEach(part => {
|
|
|
|
const path = `../${part}.ts`;
|
|
|
|
|
|
|
|
let str = fs.readFileSync(path).toString().replace(/\s.+\/\/.+/g, '');
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
2021-03-24 17:45:38 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-04 18:46:09 +00:00
|
|
|
});
|
2021-03-24 17:45:38 +00:00
|
|
|
|
|
|
|
fs.writeFileSync('./out/langPack.strings', out);
|