lila/bin/trans-dump.js

32 lines
893 B
JavaScript
Raw Normal View History

2017-05-27 03:28:28 -06:00
const fs = require('fs-extra');
const parseString = require('xml2js').parseString;
fs.readFile('translation/source/site.xml', { encoding: 'utf8' }).then(txt => {
parseString(txt, (err, xml) => {
const strings = xml.resources.string.map(e => e['$'].name);
const plurals = xml.resources.plurals.map(e => e['$'].name);
const keys = strings.concat(plurals);
const keyList = keys.map(k => 'val `' + k + '` = new Translated("' + k + '", Site)');
2017-05-27 03:28:28 -06:00
2017-05-31 01:34:48 -06:00
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 apply(db: I18nDb.Ref)(message: String) = new Translated(message, db)
def arena(message: String) = new Translated(message, I18nDb.Arena)
2017-05-27 03:28:28 -06:00
def untranslated(message: String) = new Untranslated(message)
${keyList.join('\n')}
}
`
fs.writeFile('modules/i18n/src/main/I18nKeys.scala', code);
});
});