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

simplify translate in relay and fide #16084

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions modules/fide/src/main/ui/FideUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import ScalatagsTemplate.{ *, given }

final class FideUi(helpers: Helpers)(menu: String => Context ?=> Frag):
import helpers.{ *, given }
import trans.{ site as trs, broadcast as trb }

private val tcTrans: List[(FideTC, lila.core.i18n.I18nKey)] =
List(
FideTC.standard -> trans.site.classical,
FideTC.rapid -> trans.site.rapid,
FideTC.blitz -> trans.site.blitz
FideTC.standard -> trs.classical,
FideTC.rapid -> trs.rapid,
FideTC.blitz -> trs.blitz
)

private def page(title: String, active: String)(modifiers: Modifier*)(using Context): Page =
Expand All @@ -34,15 +35,15 @@ final class FideUi(helpers: Helpers)(menu: String => Context ?=> Frag):
td(if stats.top10Rating > 0 then stats.top10Rating else "-")
page("FIDE federations", "federations")(
cls := "fide-federations",
boxTop(h1(trans.broadcast.fideFederations())),
boxTop(h1(trb.fideFederations())),
table(cls := "slist slist-pad")(
thead:
tr(
th(trans.site.name()),
th(trans.site.players()),
th(trans.site.classical()),
th(trans.site.rapid()),
th(trans.site.blitz())
th(trs.name()),
th(trs.players()),
th(trs.classical()),
th(trs.rapid()),
th(trs.blitz())
)
,
tbody(cls := "infinite-scroll")(
Expand All @@ -64,7 +65,7 @@ final class FideUi(helpers: Helpers)(menu: String => Context ?=> Frag):
cls := "fide-federation",
div(cls := "box__top fide-federation__head")(
flag(fed.id, none),
div(h1(fed.name), p(trans.site.nbPlayers.plural(fed.nbPlayers, fed.nbPlayers.localize))),
div(h1(fed.name), p(trs.nbPlayers.plural(fed.nbPlayers, fed.nbPlayers.localize))),
(fed.id.value == "KOS").option(p(cls := "fide-federation__kosovo")(kosovoText))
),
div(cls := "fide-cards fide-federation__cards box__pad")(
Expand All @@ -73,9 +74,9 @@ final class FideUi(helpers: Helpers)(menu: String => Context ?=> Frag):
card(
name(),
frag(
p(trans.site.rank(), strong(stats.get.rank)),
p(trans.broadcast.top10Rating(), strong(stats.get.top10Rating)),
p(trans.site.players(), strong(stats.get.nbPlayers.localize))
p(trs.rank(), strong(stats.get.rank)),
p(trb.top10Rating(), strong(stats.get.top10Rating)),
p(trs.players(), strong(stats.get.nbPlayers.localize))
)
)
),
Expand Down Expand Up @@ -105,7 +106,7 @@ final class FideUi(helpers: Helpers)(menu: String => Context ?=> Frag):
page("FIDE players", "players")(
cls := "fide-players",
boxTop(
h1(trans.broadcast.fidePlayers()),
h1(trb.fidePlayers()),
div(cls := "box__top__actions"):
searchForm(query)
),
Expand All @@ -116,7 +117,7 @@ final class FideUi(helpers: Helpers)(menu: String => Context ?=> Frag):
page("FIDE player not found", "players")(
cls := "fide-players",
boxTop(
h1(trans.broadcast.fidePlayerNotFound()),
h1(trb.fidePlayerNotFound()),
div(cls := "box__top__actions"):
searchForm("")
),
Expand Down Expand Up @@ -159,12 +160,12 @@ final class FideUi(helpers: Helpers)(menu: String => Context ?=> Frag):
table(cls := "slist slist-pad")(
thead:
tr(
th(trans.site.name()),
th(trs.name()),
withFlag.option(th(iconTag(Icon.FlagOutline))),
th(trans.site.classical()),
th(trans.site.rapid()),
th(trans.site.blitz()),
th(trans.broadcast.ageThisYear())
th(trs.classical()),
th(trs.rapid()),
th(trs.blitz()),
th(trb.ageThisYear())
)
,
tbody(cls := "infinite-scroll")(
Expand Down Expand Up @@ -195,23 +196,23 @@ final class FideUi(helpers: Helpers)(menu: String => Context ?=> Frag):
div(cls := "fide-cards fide-player__cards")(
player.fed.map: fed =>
card(
trans.broadcast.federation(),
trb.federation(),
a(cls := "fide-player__federation", href := routes.Fide.federation(Federation.idToSlug(fed)))(
federation.flag(fed, none),
Federation.name(fed)
)
),
card(
trans.broadcast.fideProfile(),
trb.fideProfile(),
a(href := s"https://ratings.fide.com/profile/${player.id}")(player.id)
),
card(
trans.broadcast.ageThisYear(),
trb.ageThisYear(),
player.age
),
tcTrans.map: (tc, name) =>
card(name(), player.ratingOf(tc).fold(trans.broadcast.unrated())(_.toString))
card(name(), player.ratingOf(tc).fold(trb.unrated())(_.toString))
),
tours.map: tours =>
div(cls := "fide-player__tours")(h2(trans.broadcast.recentTournaments()), tours)
div(cls := "fide-player__tours")(h2(trb.recentTournaments()), tours)
)
22 changes: 11 additions & 11 deletions modules/relay/src/main/ui/FormUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ case class FormNavigation(

final class FormUi(helpers: Helpers, ui: RelayUi, tourUi: RelayTourUi):
import helpers.{ *, given }
import trans.{ broadcast as trb }
import trans.{ broadcast as trb, site as trs }

private def navigationMenu(nav: FormNavigation)(using Context) =
def tourAndRounds(shortName: Option[RelayTour.Name]) = frag(
Expand Down Expand Up @@ -100,13 +100,13 @@ final class FormUi(helpers: Helpers, ui: RelayUi, tourUi: RelayTourUi):
)

def create(form: Form[RelayRoundForm.Data], nav: FormNavigation)(using Context) =
page(trans.broadcast.newBroadcast.txt(), nav.copy(newRound = true)):
page(trb.newBroadcast.txt(), nav.copy(newRound = true)):
frag(
boxTop(
h1(
a(href := routes.RelayTour.edit(nav.tour.id))(nav.tour.name),
" / ",
trans.broadcast.addRound()
trb.addRound()
)
),
standardFlash,
Expand Down Expand Up @@ -350,8 +350,8 @@ final class FormUi(helpers: Helpers, ui: RelayUi, tourUi: RelayTourUi):
)
),
form3.actions(
a(href := routes.RelayTour.show(nav.tour.slug, nav.tour.id))(trans.site.cancel()),
form3.submit(trans.site.apply())
a(href := routes.RelayTour.show(nav.tour.slug, nav.tour.id))(trs.cancel()),
form3.submit(trs.apply())
)
)

Expand All @@ -368,14 +368,14 @@ final class FormUi(helpers: Helpers, ui: RelayUi, tourUi: RelayTourUi):
)

def create(form: Form[lila.relay.RelayTourForm.Data])(using Context) =
page(trans.broadcast.newBroadcast.txt(), menu = Left("new")):
page(trb.newBroadcast.txt(), menu = Left("new")):
frag(
boxTop(h1(dataIcon := Icon.RadioTower, cls := "text")(trans.broadcast.newBroadcast())),
boxTop(h1(dataIcon := Icon.RadioTower, cls := "text")(trb.newBroadcast())),
postForm(cls := "form3", action := routes.RelayTour.create)(
inner(form, none),
form3.actions(
a(href := routes.RelayTour.index(1))(trans.site.cancel()),
form3.submit(trans.site.apply())
a(href := routes.RelayTour.index(1))(trs.cancel()),
form3.submit(trs.apply())
)
)
)
Expand All @@ -389,8 +389,8 @@ final class FormUi(helpers: Helpers, ui: RelayUi, tourUi: RelayTourUi):
postForm(cls := "form3", action := routes.RelayTour.update(nav.tour.id))(
inner(form, nav.tourWithGroup.some),
form3.actions(
a(href := routes.RelayTour.show(nav.tour.slug, nav.tour.id))(trans.site.cancel()),
form3.submit(trans.site.apply())
a(href := routes.RelayTour.show(nav.tour.slug, nav.tour.id))(trs.cancel()),
form3.submit(trs.apply())
)
),
div(cls := "relay-form__actions")(
Expand Down
14 changes: 7 additions & 7 deletions modules/relay/src/main/ui/RelayTourUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@ final class RelayTourUi(helpers: Helpers, ui: RelayUi):

def pageMenu(menu: String, by: Option[LightUser] = none)(using ctx: Context): Tag =
lila.ui.bits.pageMenuSubnav(
a(href := routes.RelayTour.index(), cls := menu.activeO("index"))(trans.broadcast.broadcasts()),
a(href := routes.RelayTour.index(), cls := menu.activeO("index"))(trc.broadcasts()),
ctx.me.map: me =>
a(
href := routes.RelayTour.by(me.username, 1),
cls := (menu == "new" || by.exists(_.is(me))).option("active")
):
trans.broadcast.myBroadcasts()
trc.myBroadcasts()
,
by.filterNot(ctx.is)
.map: user =>
a(href := routes.RelayTour.by(user.name, 1), cls := "active")(
user.name,
" ",
trans.broadcast.broadcasts()
trc.broadcasts()
),
a(href := routes.RelayTour.subscribed(), cls := menu.activeO("subscribed"))(
trans.broadcast.subscribedBroadcasts()
trc.subscribedBroadcasts()
),
Granter
.opt(_.StudyAdmin)
Expand All @@ -166,12 +166,12 @@ final class RelayTourUi(helpers: Helpers, ui: RelayUi):
)
),
a(href := routes.RelayTour.calendar, cls := menu.activeO("calendar"))(trans.site.tournamentCalendar()),
a(href := routes.RelayTour.help, cls := menu.activeO("help"))(trans.broadcast.aboutBroadcasts()),
a(href := routes.RelayTour.help, cls := menu.activeO("help"))(trc.aboutBroadcasts()),
a(href := routes.RelayTour.app, cls := menu.activeO("app"))("Broadcaster App"),
div(cls := "sep"),
a(cls := menu.active("players"), href := routes.Fide.index(1))(trans.broadcast.fidePlayers()),
a(cls := menu.active("players"), href := routes.Fide.index(1))(trc.fidePlayers()),
a(cls := menu.active("federations"), href := routes.Fide.federations(1))(
trans.broadcast.fideFederations()
trc.fideFederations()
)
)

Expand Down