typesafe arena FAQ translation keys

pull/3234/head
Thibault Duplessis 2017-07-06 14:40:09 +02:00
parent bd9c997375
commit ad0c903caf
3 changed files with 39 additions and 26 deletions

View File

@ -7,20 +7,20 @@
<h2>This is a private tournament</h2>
Share this URL to let people join it: @netBaseUrl@routes.Tournament.show(id)
}
@trans.arena("willBeNotified")()
@trans.arena.willBeNotified()
<h2>@trans.arena("isItRated")()</h2>
<h2>@trans.arena.isItRated()</h2>
@rated.map { r =>
@if(r) {
@trans.arena("isRated")()
@trans.arena.isRated()
} else {
@trans.arena("isNotRated")()
@trans.arena.isNotRated()
}
}.getOrElse {
@trans.arena("someRated")()
@trans.arena.someRated()
}
<h2>@trans.arena("howAreScoresCalculated")()</h2>
<h2>@trans.arena.howAreScoresCalculated()</h2>
A win has a base score of 2 points, a draw: 1 point, and a loss is worth no points.
If you win two games consecutively you will start a double point streak, known as a
<streak>Streak Starter</streak>.

View File

@ -1,15 +1,25 @@
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 baseDir = 'translation/source';
const keyList = keys.map(k => 'val `' + k + '` = new Translated("' + k + '", Site)');
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);
const code = `// Generated with bin/trans-dump.js
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
package lila.i18n
import I18nDb.Site
@ -17,15 +27,13 @@ import I18nDb.Site
// format: OFF
object I18nKeys {
def apply(db: I18nDb.Ref)(message: String) = new Translated(message, db)
def arena(message: String) = new Translated(message, I18nDb.Arena)
def untranslated(message: String) = new Untranslated(message)
${keyList.join('\n')}
object arena {
${arena}
}
`
fs.writeFile('modules/i18n/src/main/I18nKeys.scala', code);
});
${site}
}`;
fs.writeFile('modules/i18n/src/main/I18nKeys.scala', code);
});

View File

@ -6,12 +6,17 @@ import I18nDb.Site
// format: OFF
object I18nKeys {
def apply(db: I18nDb.Ref)(message: String) = new Translated(message, db)
def arena(message: String) = new Translated(message, I18nDb.Arena)
def untranslated(message: String) = new Untranslated(message)
object arena {
val `isItRated` = new Translated("isItRated", Site)
val `willBeNotified` = new Translated("willBeNotified", Site)
val `isRated` = new Translated("isRated", Site)
val `isNotRated` = new Translated("isNotRated", Site)
val `someRated` = new Translated("someRated", Site)
val `howAreScoresCalculated` = new Translated("howAreScoresCalculated", Site)
}
val `playWithAFriend` = new Translated("playWithAFriend", Site)
val `playWithTheMachine` = new Translated("playWithTheMachine", Site)
val `toInviteSomeoneToPlayGiveThisUrl` = new Translated("toInviteSomeoneToPlayGiveThisUrl", Site)
@ -600,4 +605,4 @@ val `blocks` = new Translated("blocks", Site)
val `nbForumPosts` = new Translated("nbForumPosts", Site)
val `nbPerfTypePlayersThisWeek` = new Translated("nbPerfTypePlayersThisWeek", Site)
val `availableInNbLanguages` = new Translated("availableInNbLanguages", Site)
}
}