Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use javascript assets for client i18n #16223

Merged
merged 11 commits into from
Oct 18, 2024
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project/.bloop/
conf/application.conf
conf/version.conf
conf/manifest.*

translation/js
logs
project/metals.sbt
project/project
Expand Down
13 changes: 1 addition & 12 deletions app/controllers/Dasher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ import lila.pref.ui.DasherJson

final class Dasher(env: Env)(using ws: StandaloneWSClient) extends LilaController(env):

private def translations(using ctx: Context) =
val langLang =
if LangPicker.allFromRequestHeaders(ctx.req).has(ctx.lang) then ctx.lang
else LangPicker.bestFromRequestHeaders(ctx.req) | defaultLang
lila.i18n.JsDump.keysToObject(
if ctx.isAnon then DasherJson.i18n.anon else DasherJson.i18n.auth
) ++
// the language settings should never be in a totally foreign language
lila.i18n.JsDump.keysToObject(List(trans.site.language))(using ctx.translate.copy(lang = langLang))

private lazy val galleryJson = env.memo.cacheApi.unit[Option[JsValue]]:
_.refreshAfterWrite(10.minutes).buildAsyncFuture: _ =>
ws.url(s"${env.net.assetBaseUrlInternal}/assets/lifat/background/gallery.json")
Expand All @@ -43,6 +33,5 @@ final class Dasher(env: Env)(using ws: StandaloneWSClient) extends LilaControlle
"accepted" -> LangPicker.allFromRequestHeaders(ctx.req).map(_.code),
"list" -> LangList.allChoices
),
"streamer" -> isStreamer,
"i18n" -> translations
"streamer" -> isStreamer
) ++ DasherJson(ctx.pref, gallery)
2 changes: 1 addition & 1 deletion app/views/analyse/replay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def replay(
.css((pov.game.variant == Crazyhouse).option("analyse.zh"))
.css(ctx.blind.option("round.nvui"))
.css(ctx.pref.hasKeyboardMove.option("keyboardMove"))
.i18n(_.puzzle, _.study)
.js(analyseNvuiTag)
.js(
bits.analyseModule(
"replay",
Json
.obj(
"data" -> data,
"i18n" -> views.analysisI18n(),
"userId" -> ctx.userId,
"chat" -> chatJson
)
Expand Down
2 changes: 1 addition & 1 deletion app/views/base/embed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object embed:
page.ui.pieceSprite(ctx.pieceSet.name),
cssTag("common.theme.embed"), // includes both light & dark colors
cssKeys.map(cssTag),
page.ui.sitePreload(allModules, isInquiry = false),
page.ui.sitePreload(Nil, allModules, isInquiry = false),
page.ui.lichessFontFaceCss
),
st.body(bodyModifiers)(
Expand Down
2 changes: 1 addition & 1 deletion app/views/base/page.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object page:
boardPreload,
manifests,
p.withHrefLangs.map(hrefLangs),
sitePreload(allModules, isInquiry = ctx.data.inquiry.isDefined),
sitePreload(p.i18nModules, allModules, isInquiry = ctx.data.inquiry.isDefined),
lichessFontFaceCss,
(ctx.pref.bg === lila.pref.Pref.Bg.SYSTEM).so(systemThemeScript(ctx.nonce))
),
Expand Down
1 change: 0 additions & 1 deletion app/views/board.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def userAnalysis(
Json
.obj(
"data" -> data,
"i18n" -> views.userAnalysisI18n(withForecast = withForecast),
"wiki" -> pov.game.variant.standard
)
.add("inlinePgn", inlinePgn) ++
Expand Down
1 change: 0 additions & 1 deletion app/views/insight.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def index(
Json.obj(
"ui" -> ui,
"initialQuestion" -> question,
"i18n" -> Json.obj(),
"myUserId" -> ctx.userId,
"user" -> (lila.common.Json.lightUser.write(u.light) ++ Json.obj(
"nbGames" -> insightUser.count,
Expand Down
46 changes: 0 additions & 46 deletions app/views/lobby/home.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ object home:
Json
.obj(
"data" -> data,
"i18n" -> i18nJsObject(i18nKeys),
"showRatings" -> ctx.pref.showRatings,
"hasUnreadLichessMessage" -> hasUnreadLichessMessage
)
Expand Down Expand Up @@ -165,48 +164,3 @@ object home:
views.bits.connectLinks
)
)

private val i18nKeys = List(
trans.site.realTime,
trans.site.correspondence,
trans.site.unlimited,
trans.site.timeControl,
trans.site.incrementInSeconds,
trans.site.minutesPerSide,
trans.site.daysPerTurn,
trans.site.ratingRange,
trans.site.nbPlayers,
trans.site.nbGamesInPlay,
trans.site.player,
trans.site.time,
trans.site.joinTheGame,
trans.site.cancel,
trans.site.casual,
trans.site.rated,
trans.site.perfRatingX,
trans.site.variant,
trans.site.mode,
trans.site.list,
trans.site.graph,
trans.site.filterGames,
trans.site.youNeedAnAccountToDoThat,
trans.site.oneDay,
trans.site.nbDays,
trans.site.aiNameLevelAiLevel,
trans.site.yourTurn,
trans.site.rating,
trans.site.createAGame,
trans.site.playWithAFriend,
trans.site.playWithTheMachine,
trans.site.strength,
trans.site.pasteTheFenStringHere,
trans.site.quickPairing,
trans.site.lobby,
trans.site.custom,
trans.site.anonymous,
trans.site.side,
trans.site.white,
trans.site.randomColor,
trans.site.black,
trans.site.boardEditor
)
23 changes: 2 additions & 21 deletions app/views/msg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,7 @@ import lila.app.UiEnv.{ *, given }
def home(json: JsObject)(using Context) =
Page(trans.site.inbox.txt())
.css("msg")
.js(PageModule("msg", Json.obj("data" -> json, "i18n" -> i18nJsObject(i18nKeys))))
.i18n(_.challenge)
.js(PageModule("msg", Json.obj("data" -> json)))
.csp(_.withInlineIconFont):
main(cls := "box msg-app")

private val i18nKeys = List(
trans.site.inbox,
trans.challenge.challengeToPlay,
trans.site.block,
trans.site.unblock,
trans.site.blocked,
trans.site.delete,
trans.site.reportXToModerators,
trans.site.searchOrStartNewDiscussion,
trans.site.players,
trans.site.friends,
trans.site.discussions,
trans.site.today,
trans.site.yesterday,
trans.site.youAreLeavingLichess,
trans.site.neverTypeYourPassword,
trans.site.cancel,
trans.site.proceedToX
)
2 changes: 1 addition & 1 deletion app/views/puzzle/ui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package views.puzzle
import lila.app.UiEnv.{ *, given }
import lila.puzzle.DailyPuzzle

lazy val bits = lila.puzzle.ui.PuzzleBits(helpers)(views.userAnalysisI18n.cevalTranslations)
lazy val bits = lila.puzzle.ui.PuzzleBits(helpers)
lazy val ui = lila.puzzle.ui.PuzzleUi(helpers, bits)(views.analyse.ui.csp, externalEngineEndpoint)

def embed(daily: DailyPuzzle.WithHtml)(using config: EmbedContext) =
Expand Down
1 change: 0 additions & 1 deletion app/views/relay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import lila.core.socket.SocketVersion

val ui = lila.relay.ui.RelayUi(helpers)(
picfitUrl,
views.study.jsI18n,
views.study.socketUrl,
views.board.explorerAndCevalConfig
)
Expand Down
3 changes: 1 addition & 2 deletions app/views/round/bits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package views.round
import lila.app.UiEnv.{ *, given }
import lila.game.GameExt.playerBlurPercent

lazy val ui = lila.round.ui.RoundUi(helpers, views.game.ui)
lazy val jsI18n = lila.round.ui.RoundI18n(helpers)
lazy val ui = lila.round.ui.RoundUi(helpers, views.game.ui)

def crosstable(cross: Option[lila.game.Crosstable.WithMatchup], game: Game)(using ctx: Context) =
cross.map: c =>
Expand Down
1 change: 0 additions & 1 deletion app/views/round/player.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def player(
Json
.obj(
"data" -> data,
"i18n" -> jsI18n(pov.game),
"userId" -> ctx.userId,
"chat" -> chatJson
)
Expand Down
1 change: 0 additions & 1 deletion app/views/round/watcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def watcher(
"round",
Json.obj(
"data" -> data,
"i18n" -> jsI18n(pov.game),
"chat" -> chatJson
)
)
Expand Down
9 changes: 1 addition & 8 deletions app/views/study.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ def staffPicks(p: lila.cms.CmsPage.Render)(using Context) =
def streamers(streamers: List[UserId])(using Translate) =
views.streamer.bits.contextual(streamers).map(_(cls := "none"))

def jsI18n()(using Translate) =
views.userAnalysisI18n(withAdvantageChart = true) ++
i18nJsObject(bits.i18nKeys ++ bits.gamebookPlayKeys)

def embedJsI18n(chapter: lila.study.Chapter)(using Translate) =
views.userAnalysisI18n() ++ chapter.isGamebook.so(i18nJsObject(bits.gamebookPlayKeys))

def clone(s: lila.study.Study)(using Context) =
views.site.message(title = s"Clone ${s.name}", icon = Icon.StudyBoard.some)(ui.clone(s))

Expand Down Expand Up @@ -57,6 +50,7 @@ def show(
Page(s.name.value)
.css("analyse.study")
.css(ctx.pref.hasKeyboardMove.option("keyboardMove"))
.i18n(_.study)
.js(analyseNvuiTag)
.js(
PageModule(
Expand All @@ -66,7 +60,6 @@ def show(
.add("admin", isGranted(_.StudyAdmin))
.add("showRatings", ctx.pref.showRatings),
"data" -> data.analysis,
"i18n" -> jsI18n(),
"tagTypes" -> lila.study.PgnTags.typesToString,
"userId" -> ctx.userId,
"chat" -> chatOption.map: c =>
Expand Down
2 changes: 1 addition & 1 deletion app/views/tv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index(
pov.game.variant,
s"${channel.name} TV: ${playerText(pov.player)} vs ${playerText(pov.opponent)}"
)
.js(PageModule("round", Json.obj("data" -> data, "i18n" -> views.round.jsI18n(pov.game))))
.js(PageModule("round", Json.obj("data" -> data)))
.css("bits.tv.single")
.graph(
title = s"Watch the best ${channel.name.toLowerCase} games of lichess.org",
Expand Down
4 changes: 0 additions & 4 deletions app/views/ui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ val chat = lila.chat.ChatUi(helpers)

val boardEditor = lila.web.ui.BoardEditorUi(helpers)

val userAnalysisI18n = lila.analyse.ui.AnalyseI18n(helpers)
val analysisI18n = lila.analyse.ui.GameAnalyseI18n(helpers, userAnalysisI18n)

val setup = lila.setup.ui.SetupUi(helpers)

val gathering = lila.gathering.ui.GatheringUi(helpers)(env.web.settings.prizeTournamentMakers.get)
Expand Down Expand Up @@ -55,7 +52,6 @@ object account:

val practice = lila.practice.ui.PracticeUi(helpers)(
csp = analyse.ui.csp,
translations = userAnalysisI18n.vector() ++ views.study.bits.gamebookPlayKeys,
board.explorerAndCevalConfig,
modMenu = mod.ui.menu("practice")
)
Expand Down
2 changes: 1 addition & 1 deletion app/views/user/show/page.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object page:
private def esModules(withSearch: Boolean = false)(using Context): EsmList =
import play.api.libs.json.Json
infiniteScrollEsmInit
++ esmInitObj("bits.user", "i18n" -> i18nJsObject(ui.i18nKeys))
++ esmInit("bits.user")
++ withSearch.so(Esm("bits.gameSearch"))
++ isGranted(_.UserModView).so(Esm("mod.user"))

Expand Down
3 changes: 2 additions & 1 deletion bin/schlawg-dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
cd "$(dirname "${BASH_SOURCE:-$0}")/.."

trap 'tmux kill-session -t muxlog1234 2>/dev/null' EXIT
# l=/ui-build
tmux new-session -d -s muxlog1234 \
'journalctl --user -fu lila -o cat | grep -E -v fishnet & ui/build -cdrl=/ui-build & wait; exec bash' \; \
'journalctl --user -fu lila -o cat | grep -E -v fishnet & ui/build -cdw & wait; exec bash' \; \
attach-session -d -t muxlog1234 \;
Loading
Loading