lila/bin/trans-dump.js

40 lines
1004 B
JavaScript
Raw Normal View History

2017-05-27 03:28:28 -06:00
const fs = require('fs-extra');
const parseString = require('xml2js').parseString;
2017-07-06 06:40:09 -06:00
const baseDir = 'translation/source';
2017-05-27 03:28:28 -06:00
2017-07-06 06:40:09 -06:00
function keyListFrom(file) {
return fs.readFile(`${baseDir}/${file}`, { encoding: 'utf8' }).then(txt => {
return new Promise((resolve, reject) => parseString(txt, (_, xml) => {
const strings = (xml.resources.string || []).map(e => e['$'].name);
const plurals = (xml.resources.plurals || []).map(e => e['$'].name);
const keys = strings.concat(plurals);
2017-05-27 03:28:28 -06:00
2017-07-06 06:40:09 -06:00
resolve(keys.map(k => 'val `' + k + '` = new Translated("' + k + '", Site)').join('\n'));
}));
});
}
Promise.all([
keyListFrom('site.xml'),
keyListFrom('arena.xml')
]).then(([site, arena]) => {
const code = `// Generated with bin/trans-dump.js
2017-05-27 03:28:28 -06:00
package lila.i18n
import I18nDb.Site
2017-05-27 15:31:31 -06:00
// format: OFF
2017-05-27 03:28:28 -06:00
object I18nKeys {
def untranslated(message: String) = new Untranslated(message)
2017-07-06 06:40:09 -06:00
object arena {
${arena}
2017-05-27 03:28:28 -06:00
}
2017-07-06 06:40:09 -06:00
${site}
}`;
fs.writeFile('modules/i18n/src/main/I18nKeys.scala', code);
2017-05-27 03:28:28 -06:00
});