2021-09-21 21:32:59 -06:00
|
|
|
const { readFile, writeFile } = require('fs/promises');
|
|
|
|
const { parseString } = require('xml2js');
|
2021-09-22 08:46:29 -06:00
|
|
|
const path = require('path');
|
2017-05-27 03:28:28 -06:00
|
|
|
|
2021-09-22 10:54:15 -06:00
|
|
|
const lilaDir = path.resolve(__dirname, '..');
|
2021-09-22 08:46:29 -06:00
|
|
|
const baseDir = path.resolve(lilaDir, 'translation/source');
|
2021-06-21 09:46:54 -06:00
|
|
|
const dbs =
|
2021-09-22 03:12:20 -06:00
|
|
|
'site arena emails learn activity coordinates study clas contact patron coach broadcast streamer tfa settings preferences team perfStat search tourname faq lag swiss puzzle puzzleTheme challenge storm ublog'.split(
|
|
|
|
' '
|
|
|
|
);
|
2017-05-27 03:28:28 -06:00
|
|
|
|
2017-07-06 06:46:53 -06:00
|
|
|
function ucfirst(s) {
|
2021-09-21 21:32:59 -06:00
|
|
|
return s[0].toUpperCase() + s.slice(1);
|
2017-07-06 06:46:53 -06:00
|
|
|
}
|
|
|
|
|
2020-02-07 13:21:41 -07:00
|
|
|
function xmlName(name) {
|
2021-09-21 21:32:59 -06:00
|
|
|
return name === 'clas' ? 'class' : name;
|
2020-02-07 13:21:41 -07:00
|
|
|
}
|
|
|
|
|
2017-07-06 06:46:53 -06:00
|
|
|
function keyListFrom(name) {
|
2021-09-22 08:46:29 -06:00
|
|
|
return readFile(path.resolve(baseDir, `${xmlName(name)}.xml`), { encoding: 'utf8' }).then(txt => {
|
2021-02-06 06:26:05 -07:00
|
|
|
return new Promise((resolve, reject) =>
|
|
|
|
parseString(txt, (_, xml) => {
|
2021-09-22 03:12:20 -06:00
|
|
|
const strings = (xml.resources.string || []).map(e => e['$'].name);
|
|
|
|
const plurals = (xml.resources.plurals || []).map(e => e['$'].name);
|
2021-02-06 06:26:05 -07:00
|
|
|
const keys = strings.concat(plurals);
|
2021-09-21 21:32:59 -06:00
|
|
|
|
2021-02-06 06:26:05 -07:00
|
|
|
resolve({
|
2021-09-21 21:32:59 -06:00
|
|
|
name,
|
2021-09-22 03:12:20 -06:00
|
|
|
code:
|
|
|
|
keys
|
2021-09-22 10:54:15 -06:00
|
|
|
.map(k => `val \`${k}\` = new I18nKey("${name === 'site' ? '' : xmlName(name) + ':'}${k}")`)
|
2021-09-22 03:12:20 -06:00
|
|
|
.join('\n') + '\n',
|
2021-02-06 06:26:05 -07:00
|
|
|
});
|
|
|
|
})
|
|
|
|
);
|
2017-07-06 06:40:09 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-22 03:12:20 -06:00
|
|
|
Promise.all(dbs.map(keyListFrom)).then(objs => {
|
2017-07-06 06:52:04 -06:00
|
|
|
function dbCode(obj) {
|
2021-09-21 21:32:59 -06:00
|
|
|
return obj.name === 'site' ? obj.code : `object ${obj.name} {\n${obj.code}\n}\n`;
|
2017-07-06 06:52:04 -06:00
|
|
|
}
|
2021-09-21 21:32:59 -06:00
|
|
|
|
2017-07-06 06:40:09 -06:00
|
|
|
const code = `// Generated with bin/trans-dump.js
|
2017-05-27 03:28:28 -06:00
|
|
|
package lila.i18n
|
|
|
|
|
2017-05-27 15:31:31 -06:00
|
|
|
// format: OFF
|
2017-05-27 03:28:28 -06:00
|
|
|
object I18nKeys {
|
2017-07-06 06:52:04 -06:00
|
|
|
${objs.map(dbCode).join('\n')}
|
2017-07-16 03:58:59 -06:00
|
|
|
}
|
|
|
|
`;
|
2017-07-06 06:52:04 -06:00
|
|
|
|
2021-09-22 08:46:29 -06:00
|
|
|
return writeFile(path.resolve(lilaDir, 'modules/i18n/src/main/I18nKeys.scala'), code);
|
2017-05-27 03:28:28 -06:00
|
|
|
});
|