remove Translated and Untranslated
parent
dd90d8b365
commit
255c687651
|
@ -5,7 +5,7 @@ import play.api.libs.json.JsObject
|
|||
import play.api.i18n.Lang
|
||||
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.i18n.{ I18nDb, JsDump, LangList, TimeagoLocales, Translated, Translator }
|
||||
import lila.i18n.{ I18nDb, I18nKey, JsDump, LangList, TimeagoLocales, Translator }
|
||||
import lila.user.UserContext
|
||||
|
||||
trait I18nHelper extends HasEnv with UserContext.ToLang {
|
||||
|
@ -13,10 +13,10 @@ trait I18nHelper extends HasEnv with UserContext.ToLang {
|
|||
def transKey(key: String, db: I18nDb.Ref, args: Seq[Any] = Nil)(implicit lang: Lang): Frag =
|
||||
Translator.frag.literal(key, db, args, lang)
|
||||
|
||||
def i18nJsObject(keys: Seq[Translated])(implicit lang: Lang): JsObject =
|
||||
def i18nJsObject(keys: Seq[I18nKey])(implicit lang: Lang): JsObject =
|
||||
JsDump.keysToObject(keys, lang)
|
||||
|
||||
def i18nOptionJsObject(keys: Option[Translated]*)(implicit lang: Lang): JsObject =
|
||||
def i18nOptionJsObject(keys: Option[I18nKey]*)(implicit lang: Lang): JsObject =
|
||||
JsDump.keysToObject(keys.flatten, lang)
|
||||
|
||||
def i18nFullDbJsObject(db: I18nDb.Ref)(implicit lang: Lang): JsObject =
|
||||
|
|
|
@ -3,7 +3,7 @@ package views.html.board
|
|||
import play.api.i18n.Lang
|
||||
|
||||
import lila.app.templating.Environment._
|
||||
import lila.i18n.{ Translated, I18nKeys => trans }
|
||||
import lila.i18n.{ I18nKey, I18nKeys => trans }
|
||||
|
||||
object userAnalysisI18n {
|
||||
|
||||
|
@ -24,7 +24,7 @@ object userAnalysisI18n {
|
|||
}
|
||||
)
|
||||
|
||||
private val baseTranslations: Vector[Translated] = Vector(
|
||||
private val baseTranslations: Vector[I18nKey] = Vector(
|
||||
trans.analysis,
|
||||
trans.flipBoard,
|
||||
trans.backToGame,
|
||||
|
|
|
@ -20,7 +20,7 @@ function keyListFrom(name) {
|
|||
const keys = strings.concat(plurals);
|
||||
resolve({
|
||||
name: name,
|
||||
code: keys.map(k => 'val `' + k + '` = new Translated("' + k + '", ' + ucfirst(name) + ')').join('\n') + '\n',
|
||||
code: keys.map(k => 'val `' + k + '` = new I18nKey("' + k + '", ' + ucfirst(name) + ')').join('\n') + '\n',
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
@ -40,8 +40,6 @@ import I18nDb.{ ${dbs.map(ucfirst).sort().join(', ')} }
|
|||
// format: OFF
|
||||
object I18nKeys {
|
||||
|
||||
def untranslated(message: String) = new Untranslated(message)
|
||||
|
||||
${objs.map(dbCode).join('\n')}
|
||||
}
|
||||
`;
|
||||
|
|
|
@ -3,15 +3,19 @@ package lila.i18n
|
|||
import play.api.i18n.Lang
|
||||
import scalatags.Text.RawFrag
|
||||
|
||||
sealed trait I18nKey {
|
||||
final class I18nKey(val key: String, val db: I18nDb.Ref) {
|
||||
|
||||
val key: String
|
||||
def literalTo(lang: Lang, args: Seq[Any] = Nil): RawFrag =
|
||||
Translator.frag.literal(key, db, args, lang)
|
||||
|
||||
def literalTo(lang: Lang, args: Seq[Any] = Seq.empty): RawFrag
|
||||
def pluralTo(lang: Lang, count: Count, args: Seq[Any] = Nil): RawFrag
|
||||
def pluralTo(lang: Lang, count: Count, args: Seq[Any] = Nil): RawFrag =
|
||||
Translator.frag.plural(key, db, count, args, lang)
|
||||
|
||||
def literalTxtTo(lang: Lang, args: Seq[Any] = Seq.empty): String
|
||||
def pluralTxtTo(lang: Lang, count: Count, args: Seq[Any] = Nil): String
|
||||
def literalTxtTo(lang: Lang, args: Seq[Any] = Nil): String =
|
||||
Translator.txt.literal(key, db, args, lang)
|
||||
|
||||
def pluralTxtTo(lang: Lang, count: Count, args: Seq[Any] = Nil): String =
|
||||
Translator.txt.plural(key, db, count, args, lang)
|
||||
|
||||
/* Implicit context convenience functions */
|
||||
|
||||
|
@ -26,30 +30,6 @@ sealed trait I18nKey {
|
|||
def pluralSameTxt(count: Int)(implicit lang: Lang): String = pluralTxt(count, count)
|
||||
}
|
||||
|
||||
final class Translated(val key: String, val db: I18nDb.Ref) extends I18nKey {
|
||||
|
||||
def literalTo(lang: Lang, args: Seq[Any] = Nil): RawFrag =
|
||||
Translator.frag.literal(key, db, args, lang)
|
||||
|
||||
def pluralTo(lang: Lang, count: Count, args: Seq[Any] = Nil): RawFrag =
|
||||
Translator.frag.plural(key, db, count, args, lang)
|
||||
|
||||
def literalTxtTo(lang: Lang, args: Seq[Any] = Nil): String =
|
||||
Translator.txt.literal(key, db, args, lang)
|
||||
|
||||
def pluralTxtTo(lang: Lang, count: Count, args: Seq[Any] = Nil): String =
|
||||
Translator.txt.plural(key, db, count, args, lang)
|
||||
}
|
||||
|
||||
final class Untranslated(val key: String) extends I18nKey {
|
||||
|
||||
def literalTo(lang: Lang, args: Seq[Any]) = RawFrag(key)
|
||||
def pluralTo(lang: Lang, count: Count, args: Seq[Any]) = RawFrag(key)
|
||||
|
||||
def literalTxtTo(lang: Lang, args: Seq[Any]) = key
|
||||
def pluralTxtTo(lang: Lang, count: Count, args: Seq[Any]) = key
|
||||
}
|
||||
|
||||
object I18nKey {
|
||||
|
||||
type Select = I18nKeys.type => I18nKey
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -73,7 +73,7 @@ object JsDump {
|
|||
}
|
||||
}
|
||||
|
||||
def keysToObject(keys: Seq[Translated], lang: Lang): JsObject = JsObject {
|
||||
def keysToObject(keys: Seq[I18nKey], lang: Lang): JsObject = JsObject {
|
||||
keys.flatMap { k =>
|
||||
Translator.findTranslation(k.key, k.db, lang).fold[JsTrans](Nil) { translatedJs(k.key, _) }
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.round
|
|||
|
||||
import lila.game.{ Event, Game, Pov, Progress }
|
||||
import lila.pref.{ Pref, PrefApi }
|
||||
import lila.i18n.{ I18nKeys => trans, defaultLang }
|
||||
|
||||
import chess.Centis
|
||||
import lila.common.Bus
|
||||
|
@ -13,6 +14,8 @@ final private[round] class Drawer(
|
|||
isBotSync: lila.common.LightUser.IsBotSync
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
implicit private val chatLang = defaultLang
|
||||
|
||||
def autoThreefold(game: Game): Fu[Option[Pov]] =
|
||||
Pov(game).map { pov =>
|
||||
import Pref.PrefZero
|
||||
|
@ -30,10 +33,10 @@ final private[round] class Drawer(
|
|||
case pov if pov.game.history.threefoldRepetition =>
|
||||
finisher.other(pov.game, _.Draw, None)
|
||||
case pov if pov.opponent.isOfferingDraw =>
|
||||
finisher.other(pov.game, _.Draw, None, Some(_.drawOfferAccepted))
|
||||
finisher.other(pov.game, _.Draw, None, Some(trans.drawOfferAccepted.txt()))
|
||||
case Pov(g, color) if g playerCanOfferDraw color =>
|
||||
proxy.save {
|
||||
messenger.system(g, color.fold(_.whiteOffersDraw, _.blackOffersDraw))
|
||||
messenger.system(g, color.fold(trans.whiteOffersDraw, trans.blackOffersDraw).txt())
|
||||
Progress(g) map { g =>
|
||||
g.updatePlayer(color, _ offerDraw g.turns)
|
||||
}
|
||||
|
@ -44,14 +47,14 @@ final private[round] class Drawer(
|
|||
def no(pov: Pov)(implicit proxy: GameProxy): Fu[Events] = pov match {
|
||||
case Pov(g, color) if pov.player.isOfferingDraw =>
|
||||
proxy.save {
|
||||
messenger.system(g, _.drawOfferCanceled)
|
||||
messenger.system(g, trans.drawOfferCanceled.txt())
|
||||
Progress(g) map { g =>
|
||||
g.updatePlayer(color, _.removeDrawOffer)
|
||||
}
|
||||
} inject List(Event.DrawOffer(by = none))
|
||||
case Pov(g, color) if pov.opponent.isOfferingDraw =>
|
||||
proxy.save {
|
||||
messenger.system(g, color.fold(_.whiteDeclinesDraw, _.blackDeclinesDraw))
|
||||
messenger.system(g, color.fold(trans.whiteDeclinesDraw, trans.blackDeclinesDraw).txt())
|
||||
Progress(g) map { g =>
|
||||
g.updatePlayer(!color, _.removeDrawOffer)
|
||||
}
|
||||
|
|
|
@ -53,14 +53,14 @@ final private class Finisher(
|
|||
lila.mon.round.expiration.count.increment()
|
||||
playban.noStart(Pov(game, culprit))
|
||||
if (game.isMandatory) apply(game, _.NoStart, Some(!culprit.color))
|
||||
else apply(game, _.Aborted, None, Some(_.untranslated("Game aborted by server")))
|
||||
else apply(game, _.Aborted, None, Some("Game aborted by server"))
|
||||
}
|
||||
|
||||
def other(
|
||||
game: Game,
|
||||
status: Status.type => Status,
|
||||
winner: Option[Color],
|
||||
message: Option[SelectI18nKey] = None
|
||||
message: Option[String] = None
|
||||
)(implicit proxy: GameProxy): Fu[Events] =
|
||||
apply(game, status, winner, message) >>- playban.other(game, status, winner)
|
||||
|
||||
|
@ -99,7 +99,7 @@ final private class Finisher(
|
|||
game: Game,
|
||||
makeStatus: Status.type => Status,
|
||||
@silent winnerC: Option[Color] = None,
|
||||
message: Option[SelectI18nKey] = None
|
||||
message: Option[String] = None
|
||||
)(implicit proxy: GameProxy): Fu[Events] = {
|
||||
val status = makeStatus(Status)
|
||||
val prog = game.finish(status, winnerC)
|
||||
|
|
|
@ -9,24 +9,22 @@ import lila.user.User
|
|||
|
||||
final class Messenger(api: ChatApi) {
|
||||
|
||||
def system(game: Game, message: SelectI18nKey, args: Any*): Unit =
|
||||
system(true)(game, message, args: _*)
|
||||
def system(game: Game, message: String): Unit =
|
||||
system(true)(game, message)
|
||||
|
||||
def volatile(game: Game, message: SelectI18nKey, args: Any*): Unit =
|
||||
system(false)(game, message, args: _*)
|
||||
def volatile(game: Game, message: String): Unit =
|
||||
system(false)(game, message)
|
||||
|
||||
def system(persistent: Boolean)(game: Game, message: SelectI18nKey, args: Any*): Unit = {
|
||||
val translated = message(I18nKeys).literalTxtTo(enLang, args)
|
||||
def system(persistent: Boolean)(game: Game, message: String): Unit = {
|
||||
val apiCall =
|
||||
if (persistent) api.userChat.system _
|
||||
else api.userChat.volatile _
|
||||
apiCall(watcherId(Chat.Id(game.id)), translated)
|
||||
if (game.nonAi) apiCall(Chat.Id(game.id), translated)
|
||||
apiCall(watcherId(Chat.Id(game.id)), message)
|
||||
if (game.nonAi) apiCall(Chat.Id(game.id), message)
|
||||
}
|
||||
|
||||
def systemForOwners(chatId: Chat.Id, message: SelectI18nKey, args: Any*): Unit = {
|
||||
val translated = message(I18nKeys).literalTxtTo(enLang, args)
|
||||
api.userChat.system(chatId, translated)
|
||||
def systemForOwners(chatId: Chat.Id, message: String): Unit = {
|
||||
api.userChat.system(chatId, message)
|
||||
}
|
||||
|
||||
def watcher(chatId: Chat.Id, userId: User.ID, text: String) =
|
||||
|
|
|
@ -17,7 +17,7 @@ final private class Moretimer(
|
|||
if (pov.game.hasClock) give(pov.game, List(!pov.color), duration).some
|
||||
else
|
||||
pov.game.hasCorrespondenceClock option {
|
||||
messenger.volatile(pov.game, (_.untranslated(s"${!pov.color} gets more time")))
|
||||
messenger.volatile(pov.game, s"${!pov.color} gets more time")
|
||||
val p = pov.game.correspondenceGiveTime
|
||||
p.game.correspondenceClock.map(Event.CorrespondenceClock.apply).fold(p)(p + _)
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ final private class Moretimer(
|
|||
case (c, color) => c.giveTime(color, centis)
|
||||
}
|
||||
colors.foreach { c =>
|
||||
messenger.volatile(game, (_.untranslated(s"$c + ${duration.value.toSeconds} seconds")))
|
||||
messenger.volatile(game, s"$c + ${duration.value.toSeconds} seconds")
|
||||
}
|
||||
(game withClock newClock) ++ colors.map { Event.ClockInc(_, centis) }
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import lila.common.Bus
|
|||
import lila.game.{ AnonCookie, Event, Game, GameRepo, PerfPicker, Pov, Rematches, Source }
|
||||
import lila.memo.ExpireSetMemo
|
||||
import lila.user.{ User, UserRepo }
|
||||
import lila.i18n.{ I18nKeys => trans, defaultLang }
|
||||
|
||||
final private class Rematcher(
|
||||
gameRepo: GameRepo,
|
||||
|
@ -22,6 +23,8 @@ final private class Rematcher(
|
|||
rematches: Rematches
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
implicit private val chatLang = defaultLang
|
||||
|
||||
import Rematcher.Offers
|
||||
|
||||
private val offers: Cache[Game.ID, Offers] = CacheApi.scaffeineNoScheduler
|
||||
|
@ -41,8 +44,8 @@ final private class Rematcher(
|
|||
}
|
||||
|
||||
def no(pov: Pov): Fu[Events] = {
|
||||
if (isOffering(pov)) messenger.system(pov.game, _.rematchOfferCanceled)
|
||||
else if (isOffering(!pov)) messenger.system(pov.game, _.rematchOfferDeclined)
|
||||
if (isOffering(pov)) messenger.system(pov.game, trans.rematchOfferCanceled.txt())
|
||||
else if (isOffering(!pov)) messenger.system(pov.game, trans.rematchOfferDeclined.txt())
|
||||
offers invalidate pov.game.id
|
||||
fuccess(List(Event.RematchOffer(by = none)))
|
||||
}
|
||||
|
@ -62,7 +65,7 @@ final private class Rematcher(
|
|||
_ = if (pov.game.variant == Chess960 && !chess960.get(pov.gameId)) chess960.put(nextGame.id)
|
||||
_ <- gameRepo insertDenormalized nextGame
|
||||
} yield {
|
||||
messenger.system(pov.game, _.rematchOfferAccepted)
|
||||
messenger.system(pov.game, trans.rematchOfferAccepted.txt())
|
||||
onStart(nextGame.id)
|
||||
redirectEvents(nextGame)
|
||||
}
|
||||
|
@ -70,7 +73,7 @@ final private class Rematcher(
|
|||
}
|
||||
|
||||
private def rematchCreate(pov: Pov): Events = {
|
||||
messenger.system(pov.game, _.rematchOfferSent)
|
||||
messenger.system(pov.game, trans.rematchOfferSent.txt())
|
||||
pov.opponent.userId foreach { forId =>
|
||||
Bus.publish(lila.hub.actorApi.round.RematchOffer(pov.gameId), s"rematchFor:$forId")
|
||||
}
|
||||
|
|
|
@ -441,7 +441,7 @@ final private[round] class RoundDuct(
|
|||
case WsBoot =>
|
||||
handle { game =>
|
||||
game.playable ?? {
|
||||
messenger.system(game, (_.untranslated("Lichess has been updated! Sorry for the inconvenience.")))
|
||||
messenger.system(game, "Lichess has been updated! Sorry for the inconvenience.")
|
||||
val progress = moretimer.give(game, Color.all, MoretimeDuration(20 seconds))
|
||||
proxy save progress inject progress.events
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package lila.round
|
|||
import lila.common.Bus
|
||||
import lila.game.{ Event, Game, GameRepo, Pov, Progress, Rewind, UciMemo }
|
||||
import lila.pref.{ Pref, PrefApi }
|
||||
import lila.i18n.{ I18nKeys => trans, defaultLang }
|
||||
import RoundDuct.TakebackSituation
|
||||
|
||||
final private class Takebacker(
|
||||
|
@ -12,6 +13,8 @@ final private class Takebacker(
|
|||
prefApi: PrefApi
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
implicit private val chatLang = defaultLang
|
||||
|
||||
def yes(
|
||||
situation: TakebackSituation
|
||||
)(pov: Pov)(implicit proxy: GameProxy): Fu[(Events, TakebackSituation)] = IfAllowed(pov.game) {
|
||||
|
@ -23,7 +26,7 @@ final private class Takebacker(
|
|||
case Pov(game, _) if pov.game.playableByAi => single(game) dmap (_ -> situation)
|
||||
case Pov(game, _) if pov.opponent.isAi => double(game) dmap (_ -> situation)
|
||||
case Pov(game, color) if (game playerCanProposeTakeback color) && situation.offerable => {
|
||||
messenger.system(game, _.takebackPropositionSent)
|
||||
messenger.system(game, trans.takebackPropositionSent.txt())
|
||||
val progress = Progress(game) map { g =>
|
||||
g.updatePlayer(color, _ proposeTakeback g.turns)
|
||||
}
|
||||
|
@ -38,7 +41,7 @@ final private class Takebacker(
|
|||
pov match {
|
||||
case Pov(game, color) if pov.player.isProposingTakeback =>
|
||||
proxy.save {
|
||||
messenger.system(game, _.takebackPropositionCanceled)
|
||||
messenger.system(game, trans.takebackPropositionCanceled.txt())
|
||||
Progress(game) map { g =>
|
||||
g.updatePlayer(color, _.removeTakebackProposition)
|
||||
}
|
||||
|
@ -47,7 +50,7 @@ final private class Takebacker(
|
|||
}
|
||||
case Pov(game, color) if pov.opponent.isProposingTakeback =>
|
||||
proxy.save {
|
||||
messenger.system(game, _.takebackPropositionDeclined)
|
||||
messenger.system(game, trans.takebackPropositionDeclined.txt())
|
||||
Progress(game) map { g =>
|
||||
g.updatePlayer(!color, _.removeTakebackProposition)
|
||||
}
|
||||
|
@ -109,7 +112,7 @@ final private class Takebacker(
|
|||
|
||||
private def saveAndNotify(p1: Progress)(implicit proxy: GameProxy): Fu[Events] = {
|
||||
val p2 = p1 + Event.Reload
|
||||
messenger.system(p2.game, _.takebackPropositionAccepted)
|
||||
messenger.system(p2.game, trans.takebackPropositionAccepted.txt())
|
||||
proxy.save(p2) inject p2.events
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package lila.study
|
|||
import lila.common.paginator.Paginator
|
||||
import lila.db.dsl._
|
||||
import lila.db.paginator.{ Adapter, CachedAdapter }
|
||||
import lila.i18n.{ Translated, I18nKeys => trans }
|
||||
import lila.i18n.{ I18nKey, I18nKeys => trans }
|
||||
import lila.user.User
|
||||
|
||||
final class StudyPager(
|
||||
|
@ -129,7 +129,7 @@ final class StudyPager(
|
|||
}
|
||||
}
|
||||
|
||||
sealed abstract class Order(val key: String, val name: Translated)
|
||||
sealed abstract class Order(val key: String, val name: I18nKey)
|
||||
|
||||
object Order {
|
||||
case object Hot extends Order("hot", trans.study.hot)
|
||||
|
|
Loading…
Reference in New Issue