From fad609ceaf2b2a1bed73fc2d8ec9730520aad4f4 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Fri, 26 May 2017 17:15:15 +0200 Subject: [PATCH] remove i18n subdomains, WIP --- app/Global.scala | 2 +- app/controllers/Challenge.scala | 4 +- app/controllers/Dasher.scala | 25 +++-- app/controllers/I18n.scala | 23 ++-- app/controllers/LilaController.scala | 24 ++-- app/controllers/UserAnalysis.scala | 18 +-- app/templating/AiHelper.scala | 2 +- app/templating/AnalysisHelper.scala | 7 +- app/templating/FormHelper.scala | 10 +- app/templating/GameHelper.scala | 53 ++++----- app/templating/I18hHelper.scala | 36 ++---- app/templating/SetupHelper.scala | 105 +++++++++--------- app/templating/UserHelper.scala | 19 ++-- app/views/analyse/layout.scala.html | 1 - app/views/base/layout.scala.html | 2 - app/views/blog/layout.scala.html | 3 +- app/views/board/JsData.scala | 31 +++--- app/views/challenge/mine.scala.html | 2 +- app/views/chat/chatJsData.scala | 9 +- app/views/practice/show.scala.html | 1 - app/views/puzzle/show.scala.html | 1 - app/views/round/layout.scala.html | 1 - app/views/study/listLayout.scala.html | 3 +- app/views/study/search.scala.html | 3 +- app/views/study/show.scala.html | 1 - app/views/user/mini.scala.html | 2 +- app/views/user/show.scala.html | 4 +- conf/base.conf | 3 - modules/api/src/main/Env.scala | 2 - modules/i18n/src/main/Env.scala | 38 +------ modules/i18n/src/main/I18nDomain.scala | 24 ---- modules/i18n/src/main/I18nKey.scala | 6 +- modules/i18n/src/main/I18nKeys.scala | 8 +- modules/i18n/src/main/I18nLangPicker.scala | 57 +++++----- modules/i18n/src/main/I18nPool.scala | 43 ------- .../i18n/src/main/I18nRequestHandler.scala | 44 -------- modules/i18n/src/main/JsDump.scala | 12 +- modules/i18n/src/main/LangList.scala | 10 +- modules/i18n/src/main/MessageDb.scala | 6 +- modules/i18n/src/main/Translator.scala | 18 +-- modules/i18n/src/main/package.scala | 3 + modules/round/src/main/Env.scala | 7 +- modules/round/src/main/Messenger.scala | 9 +- project/Build.scala | 1 + 44 files changed, 246 insertions(+), 437 deletions(-) delete mode 100644 modules/i18n/src/main/I18nDomain.scala delete mode 100644 modules/i18n/src/main/I18nPool.scala delete mode 100644 modules/i18n/src/main/I18nRequestHandler.scala diff --git a/app/Global.scala b/app/Global.scala index e634648cb0192..c0edfc6687d92 100644 --- a/app/Global.scala +++ b/app/Global.scala @@ -59,7 +59,7 @@ object Global extends GlobalSettings { if (lila.common.PlayApp.isProd) { lila.mon.http.response.code500() fuccess(InternalServerError(views.html.base.errorPage(ex) { - lila.api.Context(req, lila.app.Env.api.assetVersion.get, lila.i18n.I18nKey.en) + lila.api.Context(req, lila.app.Env.api.assetVersion.get, lila.i18n.defaultLang) })) } else super.onError(req, ex) } else fuccess(InternalServerError(ex.getMessage)) diff --git a/app/controllers/Challenge.scala b/app/controllers/Challenge.scala index fbace8792fc01..9bbd3850aa812 100644 --- a/app/controllers/Challenge.scala +++ b/app/controllers/Challenge.scala @@ -32,8 +32,8 @@ object Challenge extends LilaController { } private def translations(implicit ctx: Context) = Env.i18n.jsDump.keysToObject(List( - Env.i18n.keys.waiting - ), Env.i18n.pool lang ctx.req) + lila.i18n.I18nKeys.waiting + ), ctx.lang) protected[controllers] def showId(id: String)(implicit ctx: Context): Fu[Result] = OptionFuResult(env.api byId id)(showChallenge) diff --git a/app/controllers/Dasher.scala b/app/controllers/Dasher.scala index 6b3af1088668f..0332a70095fa0 100644 --- a/app/controllers/Dasher.scala +++ b/app/controllers/Dasher.scala @@ -8,26 +8,27 @@ import lila.api.Context import lila.app._ import lila.common.LightUser.lightUserWrites import lila.pref.JsonView._ +import lila.i18n.I18nKeys object Dasher extends LilaController { private def translations(implicit ctx: Context) = Env.i18n.jsDump.keysToObject( ctx.isAnon.fold( List( - Env.i18n.keys.signIn, - Env.i18n.keys.signUp + I18nKeys.signIn, + I18nKeys.signUp ), List( - Env.i18n.keys.profile, - Env.i18n.keys.inbox, - Env.i18n.keys.preferences, - Env.i18n.keys.logOut + I18nKeys.profile, + I18nKeys.inbox, + I18nKeys.preferences, + I18nKeys.logOut ) ) ::: List( - Env.i18n.keys.networkLagBetweenYouAndLichess, - Env.i18n.keys.timeToProcessAMoveOnLichessServer, - Env.i18n.keys.sound - ), Env.i18n.pool lang ctx.req + I18nKeys.networkLagBetweenYouAndLichess, + I18nKeys.timeToProcessAMoveOnLichessServer, + I18nKeys.sound + ), ctx.lang ) def get = Open { implicit ctx => @@ -37,8 +38,8 @@ object Dasher extends LilaController { Json.obj( "user" -> ctx.me.map(_.light), "lang" -> Json.obj( - "current" -> Env.i18n.pool.lang(ctx.req).language.toString, - "accepted" -> (ctx.req.acceptLanguages.map(_.language.toString)(breakOut): List[String]).distinct + "current" -> ctx.lang.code, + "accepted" -> (ctx.req.acceptLanguages.map(_.code)(breakOut): List[String]).distinct ), "sound" -> Json.obj( "list" -> lila.pref.SoundSet.list.map { set => diff --git a/app/controllers/I18n.scala b/app/controllers/I18n.scala index 04628c38d4fc8..5ea46fa1d6a2b 100644 --- a/app/controllers/I18n.scala +++ b/app/controllers/I18n.scala @@ -1,6 +1,8 @@ package controllers -import play.api.data.Form +import play.api.data._ +import play.api.data.Forms._ +import play.api.i18n.Lang import play.api.libs.json.Json import lila.app._ @@ -8,15 +10,18 @@ import lila.common.{ LilaCookie, HTTPRequest } object I18n extends LilaController { + private val form = Form(single("lang" -> text.verifying { code => + Lang.get(code) ?? lila.i18n.I18nDb.langs.contains + })) + def select = OpenBody { implicit ctx => - import play.api.data.Forms._ - import play.api.data._ implicit val req = ctx.body - Form(single("lang" -> text.verifying(Env.i18n.pool contains _))).bindFromRequest.fold( + form.bindFromRequest.fold( _ => notFound, - lang => { - ctx.me.filterNot(_.lang contains lang) ?? { me => - lila.user.UserRepo.setLang(me.id, lang) + code => { + val lang = Lang(code) + ctx.me.filterNot(_.lang contains lang.code) ?? { me => + lila.user.UserRepo.setLang(me.id, lang.code) } } >> negotiate( html = { @@ -35,10 +40,10 @@ object I18n extends LilaController { } } } - if (ctx.isAnon) redir.withCookies(LilaCookie.session("lang", lang)) + if (ctx.isAnon) redir.withCookies(LilaCookie.session("lang", lang.code)) else redir }.fuccess, - api = _ => Ok(Json.obj("lang" -> lang)).fuccess + api = _ => Ok(Json.obj("lang" -> lang.code)).fuccess ) ) } diff --git a/app/controllers/LilaController.scala b/app/controllers/LilaController.scala index 4cc33b0767afc..e1ba4677f15c5 100644 --- a/app/controllers/LilaController.scala +++ b/app/controllers/LilaController.scala @@ -41,7 +41,8 @@ private[controllers] trait LilaController api = _ => fuccess(Ok(jsonOkBody) as JSON) ) - implicit def lang(implicit req: RequestHeader) = Env.i18n.pool lang req + // implicit def lang(implicit req: RequestHeader) = Env.i18n.pool lang req + implicit def lang(implicit ctx: Context) = ctx.lang protected def NoCache(res: Result): Result = res.withHeaders( CACHE_CONTROL -> "no-cache, no-store, must-revalidate", EXPIRES -> "0" @@ -56,7 +57,7 @@ private[controllers] trait LilaController protected def Open[A](p: BodyParser[A])(f: Context => Fu[Result]): Action[A] = Action.async(p) { req => CSRF(req) { - reqToCtx(req) flatMap maybeI18nRedirect(f) + reqToCtx(req) flatMap f } } @@ -66,7 +67,7 @@ private[controllers] trait LilaController protected def OpenBody[A](p: BodyParser[A])(f: BodyContext[A] => Fu[Result]): Action[A] = Action.async(p) { req => CSRF(req) { - reqToCtx(req) flatMap maybeI18nRedirect(f) + reqToCtx(req) flatMap f } } @@ -77,9 +78,7 @@ private[controllers] trait LilaController Action.async(p) { req => CSRF(req) { reqToCtx(req) flatMap { ctx => - ctx.me.fold(authenticationFailed(ctx)) { me => - maybeI18nRedirect((c: Context) => f(c)(me))(ctx) - } + ctx.me.fold(authenticationFailed(ctx))(f(ctx)) } } } @@ -90,10 +89,8 @@ private[controllers] trait LilaController protected def AuthBody[A](p: BodyParser[A])(f: BodyContext[A] => UserModel => Fu[Result]): Action[A] = Action.async(p) { req => CSRF(req) { - reqToCtx(req) flatMap { implicit ctx => - ctx.me.fold(authenticationFailed) { me => - maybeI18nRedirect((c: BodyContext[A]) => f(c)(me))(ctx) - } + reqToCtx(req) flatMap { ctx => + ctx.me.fold(authenticationFailed(ctx))(f(ctx)) } } } @@ -122,9 +119,6 @@ private[controllers] trait LilaController protected def SecureBody(perm: Permission.type => Permission)(f: BodyContext[_] => UserModel => Fu[Result]): Action[AnyContent] = SecureBody(BodyParsers.parse.anyContent)(perm(Permission))(f) - private def maybeI18nRedirect[C <: Context](f: C => Fu[Result])(ctx: C): Fu[Result] = - Env.i18n.requestHandler(ctx.req, ctx.me, ctx.lang).fold(f(ctx))(fuccess) - protected def Firewall[A <: Result](a: => Fu[A])(implicit ctx: Context): Fu[Result] = Env.security.firewall.accepts(ctx.req) flatMap { _ fold (a, { @@ -278,13 +272,13 @@ private[controllers] trait LilaController }).dmap(_.withHeaders("Vary" -> "Accept")) protected def reqToCtx(req: RequestHeader): Fu[HeaderContext] = restoreUser(req) flatMap { d => - val ctx = UserContext(req, d.map(_.user), Env.i18n.langPicker(req, d.map(_.user))) + val ctx = UserContext(req, d.map(_.user), lila.i18n.I18nLangPicker(req, d.map(_.user))) pageDataBuilder(ctx, d.exists(_.hasFingerprint)) dmap { Context(ctx, _) } } protected def reqToCtx[A](req: Request[A]): Fu[BodyContext[A]] = restoreUser(req) flatMap { d => - val ctx = UserContext(req, d.map(_.user), Env.i18n.langPicker(req, d.map(_.user))) + val ctx = UserContext(req, d.map(_.user), lila.i18n.I18nLangPicker(req, d.map(_.user))) pageDataBuilder(ctx, d.exists(_.hasFingerprint)) dmap { Context(ctx, _) } } diff --git a/app/controllers/UserAnalysis.scala b/app/controllers/UserAnalysis.scala index 4063f21351dad..4cabbe9696327 100644 --- a/app/controllers/UserAnalysis.scala +++ b/app/controllers/UserAnalysis.scala @@ -12,6 +12,7 @@ import scala.concurrent.duration._ import lila.app._ import lila.game.{ GameRepo, Pov } +import lila.i18n.I18nKeys import lila.round.Forecast.{ forecastStepJsonFormat, forecastJsonWriter } import views._ @@ -41,19 +42,18 @@ object UserAnalysis extends LilaController with TheftPrevention { } private lazy val keyboardI18nKeys = { - val trans = Env.i18n.keys Seq( - trans.keyboardShortcuts, - trans.keyMoveBackwardOrForward, - trans.keyGoToStartOrEnd, - trans.keyShowOrHideComments, - trans.keyEnterOrExitVariation, - trans.youCanAlsoScrollOverTheBoardToMoveInTheGame, - trans.pressShiftPlusClickOrRightClickToDrawCirclesAndArrowsOnTheBoard + I18nKeys.keyboardShortcuts, + I18nKeys.keyMoveBackwardOrForward, + I18nKeys.keyGoToStartOrEnd, + I18nKeys.keyShowOrHideComments, + I18nKeys.keyEnterOrExitVariation, + I18nKeys.youCanAlsoScrollOverTheBoardToMoveInTheGame, + I18nKeys.pressShiftPlusClickOrRightClickToDrawCirclesAndArrowsOnTheBoard ) } - def keyboardI18n = Action.async { implicit req => + def keyboardI18n = Open { implicit ctx => JsonOk(fuccess(Env.i18n.jsDump.keysToObject(keyboardI18nKeys, lang))) } diff --git a/app/templating/AiHelper.scala b/app/templating/AiHelper.scala index d3153a6db7b42..38f2bb73530cf 100644 --- a/app/templating/AiHelper.scala +++ b/app/templating/AiHelper.scala @@ -8,7 +8,7 @@ import lila.user.UserContext trait AiHelper { self: I18nHelper => def aiName(level: Int, withRating: Boolean = true)(implicit ctx: UserContext): String = { - val name = trans.aiNameLevelAiLevel.str("Stockfish AI", level) + val name = lila.i18n.I18nKeys.aiNameLevelAiLevel.str("Stockfish AI", level) val rating = withRating ?? { aiRating(level) ?? { r => s" ($r)" } } diff --git a/app/templating/AnalysisHelper.scala b/app/templating/AnalysisHelper.scala index 1cfb446716e28..048f9fc6e0570 100644 --- a/app/templating/AnalysisHelper.scala +++ b/app/templating/AnalysisHelper.scala @@ -4,13 +4,14 @@ package templating import lila.analyse.Advice.Judgment import lila.api.Context +import lila.i18n.I18nKeys trait AnalysisHelper { self: I18nHelper with SecurityHelper => def judgmentName(judgment: Judgment)(implicit ctx: Context) = judgment match { - case Judgment.Blunder => trans.blunders() - case Judgment.Mistake => trans.mistakes() - case Judgment.Inaccuracy => trans.inaccuracies() + case Judgment.Blunder => I18nKeys.blunders() + case Judgment.Mistake => I18nKeys.mistakes() + case Judgment.Inaccuracy => I18nKeys.inaccuracies() case judgment => judgment.toString } } diff --git a/app/templating/FormHelper.scala b/app/templating/FormHelper.scala index 065756943d243..13cba03a73e4b 100644 --- a/app/templating/FormHelper.scala +++ b/app/templating/FormHelper.scala @@ -1,16 +1,18 @@ package lila.app package templating -import lila.api.Context import play.api.data._ import play.twirl.api.Html +import lila.api.Context +import lila.i18n.I18nKeys + trait FormHelper { self: I18nHelper => private val errNames = Map( - "error.minLength" -> trans.textIsTooShort, - "error.maxLength" -> trans.textIsTooLong, - "captcha.fail" -> trans.notACheckmate + "error.minLength" -> I18nKeys.textIsTooShort, + "error.maxLength" -> I18nKeys.textIsTooLong, + "captcha.fail" -> I18nKeys.notACheckmate ) def errMsg(form: Field)(implicit ctx: Context): Html = errMsg(form.errors) diff --git a/app/templating/GameHelper.scala b/app/templating/GameHelper.scala index a997fd23b9a50..aba74bf3227d6 100644 --- a/app/templating/GameHelper.scala +++ b/app/templating/GameHelper.scala @@ -8,6 +8,7 @@ import play.twirl.api.Html import lila.game.{ Game, Player, Namer, Pov } import lila.user.{ User, UserContext } +import lila.i18n.I18nKeys trait GameHelper { self: I18nHelper with UserHelper with AiHelper with StringHelper with ChessgroundHelper => @@ -64,30 +65,30 @@ trait GameHelper { self: I18nHelper with UserHelper with AiHelper with StringHel } def variantName(variant: chess.variant.Variant)(implicit ctx: UserContext) = variant match { - case chess.variant.Standard => trans.standard.str() - case chess.variant.FromPosition => trans.fromPosition.str() + case chess.variant.Standard => I18nKeys.standard.str() + case chess.variant.FromPosition => I18nKeys.fromPosition.str() case v => v.name } def variantNameNoCtx(variant: chess.variant.Variant) = variant match { - case chess.variant.Standard => trans.standard.en() - case chess.variant.FromPosition => trans.fromPosition.en() + case chess.variant.Standard => I18nKeys.standard.en() + case chess.variant.FromPosition => I18nKeys.fromPosition.en() case v => v.name } def shortClockName(clock: Option[Clock.Config])(implicit ctx: UserContext): Html = - clock.fold(trans.unlimited())(shortClockName) + clock.fold(I18nKeys.unlimited())(shortClockName) def shortClockName(clock: Clock.Config): Html = Html(clock.show) def modeName(mode: Mode)(implicit ctx: UserContext): String = mode match { - case Mode.Casual => trans.casual.str() - case Mode.Rated => trans.rated.str() + case Mode.Casual => I18nKeys.casual.str() + case Mode.Rated => I18nKeys.rated.str() } def modeNameNoCtx(mode: Mode): String = mode match { - case Mode.Casual => trans.casual.en() - case Mode.Rated => trans.rated.en() + case Mode.Casual => I18nKeys.casual.en() + case Mode.Rated => I18nKeys.rated.en() } def playerUsername(player: Player, withRating: Boolean = true, withTitle: Boolean = true) = @@ -133,7 +134,7 @@ trait GameHelper { self: I18nHelper with UserHelper with AiHelper with StringHel val href = s"${routes.User show user.name}${if (mod) "?mod" else ""}" val content = playerUsername(player, withRating) val diff = (player.ratingDiff ifTrue withDiff).fold(Html(""))(showRatingDiff) - val mark = engine ?? s"""""" + val mark = engine ?? s"""""" val dataIcon = withOnline ?? """data-icon="r"""" val space = if (withOnline) " " else "" val tag = if (link) "a" else "span" @@ -142,31 +143,31 @@ trait GameHelper { self: I18nHelper with UserHelper with AiHelper with StringHel } def gameEndStatus(game: Game)(implicit ctx: UserContext): Html = game.status match { - case S.Aborted => trans.gameAborted() - case S.Mate => trans.checkmate() + case S.Aborted => I18nKeys.gameAborted() + case S.Mate => I18nKeys.checkmate() case S.Resign => game.loser match { - case Some(p) if p.color.white => trans.whiteResigned() - case _ => trans.blackResigned() + case Some(p) if p.color.white => I18nKeys.whiteResigned() + case _ => I18nKeys.blackResigned() } - case S.UnknownFinish => trans.finished() - case S.Stalemate => trans.stalemate() + case S.UnknownFinish => I18nKeys.finished() + case S.Stalemate => I18nKeys.stalemate() case S.Timeout => game.loser match { - case Some(p) if p.color.white => trans.whiteLeftTheGame() - case Some(_) => trans.blackLeftTheGame() - case None => trans.draw() + case Some(p) if p.color.white => I18nKeys.whiteLeftTheGame() + case Some(_) => I18nKeys.blackLeftTheGame() + case None => I18nKeys.draw() } - case S.Draw => trans.draw() - case S.Outoftime => trans.timeOut() + case S.Draw => I18nKeys.draw() + case S.Outoftime => I18nKeys.timeOut() case S.NoStart => Html { val color = game.loser.fold(Color.white)(_.color).name.capitalize s"$color didn't move" } case S.Cheat => Html("Cheat detected") case S.VariantEnd => game.variant match { - case chess.variant.KingOfTheHill => trans.kingInTheCenter() - case chess.variant.ThreeCheck => trans.threeChecks() - case chess.variant.RacingKings => trans.raceFinished() - case _ => trans.variantEnding() + case chess.variant.KingOfTheHill => I18nKeys.kingInTheCenter() + case chess.variant.ThreeCheck => I18nKeys.threeChecks() + case chess.variant.RacingKings => I18nKeys.raceFinished() + case _ => I18nKeys.variantEnding() } case _ => Html("") } @@ -240,7 +241,7 @@ trait GameHelper { self: I18nHelper with UserHelper with AiHelper with StringHel } def challengeTitle(c: lila.challenge.Challenge)(implicit ctx: UserContext) = { - val speed = c.clock.map(_.config).fold(trans.unlimited.str()) { clock => + val speed = c.clock.map(_.config).fold(I18nKeys.unlimited.str()) { clock => s"${chess.Speed(clock).name} (${clock.show})" } val variant = c.variant.exotic ?? s" ${c.variant.name}" diff --git a/app/templating/I18hHelper.scala b/app/templating/I18hHelper.scala index 87baf4f471e05..6be2725ada912 100644 --- a/app/templating/I18hHelper.scala +++ b/app/templating/I18hHelper.scala @@ -8,20 +8,15 @@ import play.api.libs.json.JsObject import play.twirl.api.Html import lila.i18n.Env.{ current => i18nEnv } -import lila.i18n.{ LangList, I18nDomain, I18nKey } +import lila.i18n.{ LangList, I18nKey, Translator } import lila.user.UserContext trait I18nHelper { - private def pool = i18nEnv.pool - - lazy val trans = i18nEnv.keys - lazy val protocol = i18nEnv.RequestHandlerProtocol - - implicit def lang(implicit ctx: UserContext) = pool lang ctx.req + implicit def lang(implicit ctx: UserContext) = ctx.lang def transKey(key: String, args: Seq[Any] = Nil)(implicit lang: Lang): String = - i18nEnv.translator.transTo(key, args, lang) + Translator.transTo(key, args, lang) def i18nJsObjectMessage(keys: Seq[I18nKey])(implicit lang: Lang): JsObject = i18nEnv.jsDump.keysToMessageObject(keys, lang) @@ -32,29 +27,12 @@ trait I18nHelper { def i18nOptionJsObject(keys: Option[I18nKey]*)(implicit lang: Lang): JsObject = i18nEnv.jsDump.keysToObject(keys.flatten, lang) - def langName(lang: Lang): Option[String] = langName(lang.language) - def langName(lang: String): Option[String] = LangList name lang - - def shortLangName(lang: Lang): Option[String] = shortLangName(lang.language) - def shortLangName(lang: String): Option[String] = langName(lang) map (_ takeWhile (','!=)) - - def transValidationPattern(trans: String) = - (trans contains "%s") option ".*%s.*" + // def langName(lang: Lang): Option[String] = langName(lang.language) + def langName = LangList.nameByStr _ - private lazy val langAnnotationsBase: String = - pool.names.keySet diff Set("fp", "kb", "le", "tp", "pi", "io") map { code => - s"""""" - } mkString "" - - def langAnnotations(implicit ctx: UserContext) = Html { - langAnnotationsBase.replace("%", ctx.req.uri) - } - - def commonDomain(implicit ctx: UserContext): String = - I18nDomain(ctx.req.domain).commonDomain + // def shortLangName(lang: Lang): Option[String] = shortLangName(lang.language) + def shortLangName(str: String) = langName(str).takeWhile(','!=) def acceptsLanguage(lang: Lang)(implicit ctx: UserContext): Boolean = ctx.req.acceptLanguages exists (_.language == lang.language) - - private val uriPlaceholder = "[URI]" } diff --git a/app/templating/SetupHelper.scala b/app/templating/SetupHelper.scala index 19b774ba95c2c..63931898ff32a 100644 --- a/app/templating/SetupHelper.scala +++ b/app/templating/SetupHelper.scala @@ -7,25 +7,26 @@ import lila.pref.Pref import lila.report.Reason import lila.setup.TimeMode import lila.tournament.System +import lila.i18n.I18nKeys trait SetupHelper { self: I18nHelper => def translatedTimeModeChoices(implicit ctx: Context) = List( - (TimeMode.RealTime.id.toString, trans.realTime.str(), none), - (TimeMode.Correspondence.id.toString, trans.correspondence.str(), none), - (TimeMode.Unlimited.id.toString, trans.unlimited.str(), none) + (TimeMode.RealTime.id.toString, I18nKeys.realTime.str(), none), + (TimeMode.Correspondence.id.toString, I18nKeys.correspondence.str(), none), + (TimeMode.Unlimited.id.toString, I18nKeys.unlimited.str(), none) ) def translatedReasonChoices(implicit ctx: Context) = List( - (Reason.Cheat.key, trans.cheat.str()), - (Reason.Insult.key, trans.insult.str()), - (Reason.Troll.key, trans.troll.str()), - (Reason.Other.key, trans.other.str()) + (Reason.Cheat.key, I18nKeys.cheat.str()), + (Reason.Insult.key, I18nKeys.insult.str()), + (Reason.Troll.key, I18nKeys.troll.str()), + (Reason.Other.key, I18nKeys.other.str()) ) def translatedModeChoices(implicit ctx: Context) = List( - (Mode.Casual.id.toString, trans.casual.str(), none), - (Mode.Rated.id.toString, trans.rated.str(), none) + (Mode.Casual.id.toString, I18nKeys.casual.str(), none), + (Mode.Rated.id.toString, I18nKeys.rated.str(), none) ) def translatedSystemChoices(implicit ctx: Context) = List( @@ -36,7 +37,7 @@ trait SetupHelper { self: I18nHelper => (variant.id.toString, variant.name, variant.title.some) def translatedVariantChoices(implicit ctx: Context) = List( - (chess.variant.Standard.id.toString, trans.standard.str(), chess.variant.Standard.title.some) + (chess.variant.Standard.id.toString, I18nKeys.standard.str(), chess.variant.Standard.title.some) ) def translatedVariantChoicesWithVariants(implicit ctx: Context) = @@ -74,88 +75,88 @@ trait SetupHelper { self: I18nHelper => def translatedSpeedChoices(implicit ctx: Context) = Speed.limited map { s => (s.id.toString, { (s.range.min, s.range.max) match { - case (0, y) => s.toString + " - " + trans.lessThanNbMinutes(y / 60 + 1) - case (x, y) => s.toString + " - " + trans.xToYMinutes(x / 60, y / 60 + 1) + case (0, y) => s.toString + " - " + I18nKeys.lessThanNbMinutes(y / 60 + 1) + case (x, y) => s.toString + " - " + I18nKeys.xToYMinutes(x / 60, y / 60 + 1) } }, none) } def translatedAnimationChoices(implicit ctx: Context) = List( - (Pref.Animation.NONE, trans.none.str()), - (Pref.Animation.FAST, trans.fast.str()), - (Pref.Animation.NORMAL, trans.normal.str()), - (Pref.Animation.SLOW, trans.slow.str()) + (Pref.Animation.NONE, I18nKeys.none.str()), + (Pref.Animation.FAST, I18nKeys.fast.str()), + (Pref.Animation.NORMAL, I18nKeys.normal.str()), + (Pref.Animation.SLOW, I18nKeys.slow.str()) ) def translatedBoardCoordinateChoices(implicit ctx: Context) = List( - (Pref.Coords.NONE, trans.no.str()), - (Pref.Coords.INSIDE, trans.insideTheBoard.str()), - (Pref.Coords.OUTSIDE, trans.outsideTheBoard.str()) + (Pref.Coords.NONE, I18nKeys.no.str()), + (Pref.Coords.INSIDE, I18nKeys.insideTheBoard.str()), + (Pref.Coords.OUTSIDE, I18nKeys.outsideTheBoard.str()) ) def translatedMoveListWhilePlayingChoices(implicit ctx: Context) = List( - (Pref.Replay.NEVER, trans.never.str()), - (Pref.Replay.SLOW, trans.onSlowGames.str()), - (Pref.Replay.ALWAYS, trans.always.str()) + (Pref.Replay.NEVER, I18nKeys.never.str()), + (Pref.Replay.SLOW, I18nKeys.onSlowGames.str()), + (Pref.Replay.ALWAYS, I18nKeys.always.str()) ) def translatedClockTenthsChoices(implicit ctx: Context) = List( - (Pref.ClockTenths.NEVER, trans.never.str()), - (Pref.ClockTenths.LOWTIME, trans.whenTimeRemainingLessThanTenSeconds.str()), - (Pref.ClockTenths.ALWAYS, trans.always.str()) + (Pref.ClockTenths.NEVER, I18nKeys.never.str()), + (Pref.ClockTenths.LOWTIME, I18nKeys.whenTimeRemainingLessThanTenSeconds.str()), + (Pref.ClockTenths.ALWAYS, I18nKeys.always.str()) ) def translatedTakebackChoices(implicit ctx: Context) = List( - (Pref.Takeback.NEVER, trans.never.str()), - (Pref.Takeback.ALWAYS, trans.always.str()), - (Pref.Takeback.CASUAL, trans.inCasualGamesOnly.str()) + (Pref.Takeback.NEVER, I18nKeys.never.str()), + (Pref.Takeback.ALWAYS, I18nKeys.always.str()), + (Pref.Takeback.CASUAL, I18nKeys.inCasualGamesOnly.str()) ) def translatedAutoQueenChoices(implicit ctx: Context) = List( - (Pref.AutoQueen.NEVER, trans.never.str()), - (Pref.AutoQueen.PREMOVE, trans.whenPremoving.str()), - (Pref.AutoQueen.ALWAYS, trans.always.str()) + (Pref.AutoQueen.NEVER, I18nKeys.never.str()), + (Pref.AutoQueen.PREMOVE, I18nKeys.whenPremoving.str()), + (Pref.AutoQueen.ALWAYS, I18nKeys.always.str()) ) def translatedAutoThreefoldChoices(implicit ctx: Context) = List( - (Pref.AutoThreefold.NEVER, trans.never.str()), - (Pref.AutoThreefold.ALWAYS, trans.always.str()), - (Pref.AutoThreefold.TIME, trans.whenTimeRemainingLessThanThirtySeconds.str()) + (Pref.AutoThreefold.NEVER, I18nKeys.never.str()), + (Pref.AutoThreefold.ALWAYS, I18nKeys.always.str()), + (Pref.AutoThreefold.TIME, I18nKeys.whenTimeRemainingLessThanThirtySeconds.str()) ) def submitMoveChoices(implicit ctx: Context) = List( - (Pref.SubmitMove.NEVER, trans.never.str()), - (Pref.SubmitMove.CORRESPONDENCE_ONLY, trans.inCorrespondenceGames.str()), - (Pref.SubmitMove.CORRESPONDENCE_UNLIMITED, trans.correspondenceAndUnlimited.str()), - (Pref.SubmitMove.ALWAYS, trans.always.str()) + (Pref.SubmitMove.NEVER, I18nKeys.never.str()), + (Pref.SubmitMove.CORRESPONDENCE_ONLY, I18nKeys.inCorrespondenceGames.str()), + (Pref.SubmitMove.CORRESPONDENCE_UNLIMITED, I18nKeys.correspondenceAndUnlimited.str()), + (Pref.SubmitMove.ALWAYS, I18nKeys.always.str()) ) def confirmResignChoices(implicit ctx: Context) = List( - (Pref.ConfirmResign.NO, trans.no.str()), - (Pref.ConfirmResign.YES, trans.yes.str()) + (Pref.ConfirmResign.NO, I18nKeys.no.str()), + (Pref.ConfirmResign.YES, I18nKeys.yes.str()) ) def translatedChallengeChoices(implicit ctx: Context) = List( - (Pref.Challenge.NEVER, trans.never.str()), - (Pref.Challenge.RATING, trans.ifRatingIsPlusMinusX(lila.pref.Pref.Challenge.ratingThreshold).toString()), - (Pref.Challenge.FRIEND, trans.onlyFriends.str()), - (Pref.Challenge.ALWAYS, trans.always.str()) + (Pref.Challenge.NEVER, I18nKeys.never.str()), + (Pref.Challenge.RATING, I18nKeys.ifRatingIsPlusMinusX(lila.pref.Pref.Challenge.ratingThreshold).toString()), + (Pref.Challenge.FRIEND, I18nKeys.onlyFriends.str()), + (Pref.Challenge.ALWAYS, I18nKeys.always.str()) ) def translatedMessageChoices(implicit ctx: Context) = List( - (Pref.Message.NEVER, trans.never.str()), - (Pref.Message.FRIEND, trans.onlyFriends.str()), - (Pref.Message.ALWAYS, trans.always.str()) + (Pref.Message.NEVER, I18nKeys.never.str()), + (Pref.Message.FRIEND, I18nKeys.onlyFriends.str()), + (Pref.Message.ALWAYS, I18nKeys.always.str()) ) def translatedStudyInviteChoices(implicit ctx: Context) = List( - (Pref.StudyInvite.NEVER, trans.never.str()), - (Pref.StudyInvite.FRIEND, trans.onlyFriends.str()), - (Pref.StudyInvite.ALWAYS, trans.always.str()) + (Pref.StudyInvite.NEVER, I18nKeys.never.str()), + (Pref.StudyInvite.FRIEND, I18nKeys.onlyFriends.str()), + (Pref.StudyInvite.ALWAYS, I18nKeys.always.str()) ) def translatedBlindfoldChoices(implicit ctx: Context) = List( - Pref.Blindfold.NO -> trans.no.str(), - Pref.Blindfold.YES -> trans.yes.str() + Pref.Blindfold.NO -> I18nKeys.no.str(), + Pref.Blindfold.YES -> I18nKeys.yes.str() ) } diff --git a/app/templating/UserHelper.scala b/app/templating/UserHelper.scala index feb3b587da5f0..99a6048a48917 100644 --- a/app/templating/UserHelper.scala +++ b/app/templating/UserHelper.scala @@ -9,6 +9,7 @@ import lila.api.Context import lila.common.LightUser import lila.rating.{ PerfType, Perf } import lila.user.{ User, UserContext } +import lila.i18n.I18nKeys trait UserHelper { self: I18nHelper with StringHelper with NumberHelper => @@ -248,16 +249,16 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper => splitNumber(userGameFilterTitleNoTag(info, filter)) def userGameFilterTitleNoTag(info: UserInfo, filter: GameFilter)(implicit ctx: UserContext) = Html((filter match { - case GameFilter.All => info.user.count.game + " " + trans.gamesPlayed() - case GameFilter.Me => ctx.me ?? (me => trans.nbGamesWithYou.str(info.nbWithMe)) - case GameFilter.Rated => info.nbRated + " " + trans.rated() - case GameFilter.Win => trans.nbWins(info.user.count.win) - case GameFilter.Loss => trans.nbLosses(info.user.count.loss) - case GameFilter.Draw => trans.nbDraws(info.user.count.draw) + case GameFilter.All => info.user.count.game + " " + I18nKeys.gamesPlayed() + case GameFilter.Me => ctx.me ?? (me => I18nKeys.nbGamesWithYou.str(info.nbWithMe)) + case GameFilter.Rated => info.nbRated + " " + I18nKeys.rated() + case GameFilter.Win => I18nKeys.nbWins(info.user.count.win) + case GameFilter.Loss => I18nKeys.nbLosses(info.user.count.loss) + case GameFilter.Draw => I18nKeys.nbDraws(info.user.count.draw) case GameFilter.Playing => info.nbPlaying + " playing" - case GameFilter.Bookmark => trans.nbBookmarks(info.nbBookmark) - case GameFilter.Imported => trans.nbImportedGames(info.nbImported) - case GameFilter.Search => Html(trans.advancedSearch.str().replaceFirst(" ", "\n")) + case GameFilter.Bookmark => I18nKeys.nbBookmarks(info.nbBookmark) + case GameFilter.Imported => I18nKeys.nbImportedGames(info.nbImported) + case GameFilter.Search => Html(I18nKeys.advancedSearch.str().replaceFirst(" ", "\n")) }).toString) def describeUser(user: User) = { diff --git a/app/views/analyse/layout.scala.html b/app/views/analyse/layout.scala.html index 2dcc42d3aca10..2aa2db0b533ce 100644 --- a/app/views/analyse/layout.scala.html +++ b/app/views/analyse/layout.scala.html @@ -10,6 +10,5 @@ openGraph = openGraph, chessground = chessground, robots = false, -withLangAnnotations = false, atom = atom, zoomable = true)(body) diff --git a/app/views/base/layout.scala.html b/app/views/base/layout.scala.html index 5d5770cfce1a8..e7cfab7eab229 100644 --- a/app/views/base/layout.scala.html +++ b/app/views/base/layout.scala.html @@ -14,7 +14,6 @@ openGraph: Option[lila.app.ui.OpenGraph] = None, atom: Option[Html] = None, chessground: Boolean = true, -withLangAnnotations: Boolean = true, zoomable: Boolean = false, asyncJs: Boolean = false)(body: Html)(implicit ctx: Context) @@ -52,7 +51,6 @@ } - @if(withLangAnnotations && ctx.isAnon && lila.common.HTTPRequest.isBot(ctx.req)){@langAnnotations} @ctx.transpBgImg.map { img => } diff --git a/app/views/blog/layout.scala.html b/app/views/blog/layout.scala.html index 955ed3b175985..2839df767fecf 100644 --- a/app/views/blog/layout.scala.html +++ b/app/views/blog/layout.scala.html @@ -5,8 +5,7 @@ moreCss = cssTag("blog.css"), moreJs = jsTag("embed-analyse.js"), side = side, -openGraph = openGraph, -withLangAnnotations = false) { +openGraph = openGraph) {
@body
diff --git a/app/views/board/JsData.scala b/app/views/board/JsData.scala index 45b40d97906df..b7d498f192cbb 100644 --- a/app/views/board/JsData.scala +++ b/app/views/board/JsData.scala @@ -6,6 +6,7 @@ import scala.concurrent.duration.Duration import lila.api.Context import lila.app.templating.Environment._ +import lila.i18n.I18nKeys object JsData extends lila.Steroids { @@ -28,21 +29,21 @@ object JsData extends lila.Steroids { ), "is3d" -> ctx.pref.is3d, "i18n" -> i18nJsObject( - trans.startPosition, - trans.clearBoard, - trans.flipBoard, - trans.loadPosition, - trans.castling, - trans.whiteCastlingKingside, - trans.whiteCastlingQueenside, - trans.blackCastlingKingside, - trans.blackCastlingQueenside, - trans.whitePlays, - trans.blackPlays, - trans.continueFromHere, - trans.playWithTheMachine, - trans.playWithAFriend, - trans.analysis + I18nKeys.startPosition, + I18nKeys.clearBoard, + I18nKeys.flipBoard, + I18nKeys.loadPosition, + I18nKeys.castling, + I18nKeys.whiteCastlingKingside, + I18nKeys.whiteCastlingQueenside, + I18nKeys.blackCastlingKingside, + I18nKeys.blackCastlingQueenside, + I18nKeys.whitePlays, + I18nKeys.blackPlays, + I18nKeys.continueFromHere, + I18nKeys.playWithTheMachine, + I18nKeys.playWithAFriend, + I18nKeys.analysis ) ) } diff --git a/app/views/challenge/mine.scala.html b/app/views/challenge/mine.scala.html index e04cb9c577493..4280c9d78e7a4 100644 --- a/app/views/challenge/mine.scala.html +++ b/app/views/challenge/mine.scala.html @@ -27,7 +27,7 @@

@trans.challengeToPlay()

@cancelForm }.getOrElse { @trans.toInviteSomeoneToPlayGiveThisUrl(): - +
@trans.theFirstPersonToComeOnThisUrlWillPlayWithYou() diff --git a/app/views/chat/chatJsData.scala b/app/views/chat/chatJsData.scala index 09b036817c91c..900f631cc9ba7 100644 --- a/app/views/chat/chatJsData.scala +++ b/app/views/chat/chatJsData.scala @@ -5,6 +5,7 @@ import play.api.libs.json.Json import lila.api.Context import lila.app.templating.Environment._ import lila.common.PimpedJson._ +import lila.i18n.I18nKeys object ChatJsData { @@ -51,9 +52,9 @@ object ChatJsData { ) def i18n(withNote: Boolean)(implicit ctx: Context) = i18nOptionJsObject( - trans.talkInChat.some, - trans.toggleTheChat.some, - withNote option trans.notes, - withNote option trans.typePrivateNotesHere + I18nKeys.talkInChat.some, + I18nKeys.toggleTheChat.some, + withNote option I18nKeys.notes, + withNote option I18nKeys.typePrivateNotesHere ) } diff --git a/app/views/practice/show.scala.html b/app/views/practice/show.scala.html index aaf72c95034fe..28481e8d78ea9 100644 --- a/app/views/practice/show.scala.html +++ b/app/views/practice/show.scala.html @@ -34,7 +34,6 @@ moreCss = moreCss, moreJs = moreJs, chessground = false, -withLangAnnotations = false, zoomable = true) {
@miniBoardContent
} diff --git a/app/views/puzzle/show.scala.html b/app/views/puzzle/show.scala.html index ec197bdad6a69..ec7dcb02bfdfd 100644 --- a/app/views/puzzle/show.scala.html +++ b/app/views/puzzle/show.scala.html @@ -28,7 +28,6 @@ moreCss = moreCss, moreJs = moreJs, chessground = false, -withLangAnnotations = false, openGraph = lila.app.ui.OpenGraph( image = cdnUrl(routes.Export.puzzlePng(puzzle.id).url).some, title = s"Chess tactic #${puzzle.id} - ${puzzle.color.name.capitalize} to play", diff --git a/app/views/round/layout.scala.html b/app/views/round/layout.scala.html index 6e05baf1be0ba..d8a846cea43b3 100644 --- a/app/views/round/layout.scala.html +++ b/app/views/round/layout.scala.html @@ -11,7 +11,6 @@ chessground = chessground, playing = playing, robots = false, -withLangAnnotations = false, atom = atom, asyncJs = true, zoomable = true)(body) diff --git a/app/views/study/listLayout.scala.html b/app/views/study/listLayout.scala.html index 35420a3d9532d..8772947d6414a 100644 --- a/app/views/study/listLayout.scala.html +++ b/app/views/study/listLayout.scala.html @@ -20,8 +20,7 @@ title = title, menu = menu.some, moreCss = moreCss, -moreJs = moreJs, -withLangAnnotations = false) { +moreJs = moreJs) {