challenge reasons WIP, move challenge i18n to new file - for #7487 #7658

challenge-reason
Thibault Duplessis 2021-01-21 13:23:08 +01:00
parent 976163c0fa
commit d2b38f04d9
17 changed files with 64 additions and 46 deletions

View File

@ -91,7 +91,7 @@ object layout {
private def allNotifications(implicit ctx: Context) =
spaceless(s"""<div>
<a id="challenge-toggle" class="toggle link">
<span title="${trans.challenges
<span title="${trans.challenge.challenges
.txt()}" class="data-count" data-count="${ctx.nbChallenges}" data-icon="U"></span>
</a>
<div id="challenge-app" class="dropdown"></div>

View File

@ -29,7 +29,7 @@ object mine {
c.status match {
case Status.Created | Status.Offline =>
div(id := "ping-challenge")(
h1(if (c.isOpen) "Open challenge" else trans.challengeToPlay.txt()),
h1(if (c.isOpen) "Open challenge" else trans.challenge.challengeToPlay.txt()),
bits.details(c),
c.destUserId.map { destId =>
div(cls := "waiting")(
@ -93,13 +93,13 @@ object mine {
)
case Status.Declined =>
div(cls := "follow-up")(
h1(trans.challengeDeclined()),
h1(trans.challenge.challengeDeclined()),
bits.details(c),
a(cls := "button button-fat", href := routes.Lobby.home())(trans.newOpponent())
)
case Status.Accepted =>
div(cls := "follow-up")(
h1(trans.challengeAccepted()),
h1(trans.challenge.challengeAccepted()),
bits.details(c),
a(id := "challenge-redirect", href := routes.Round.watcher(c.id, "white"), cls := "button-fat")(
trans.joinTheGame()
@ -107,7 +107,7 @@ object mine {
)
case Status.Canceled =>
div(cls := "follow-up")(
h1(trans.challengeCanceled()),
h1(trans.challenge.challengeCanceled()),
bits.details(c),
a(cls := "button button-fat", href := routes.Lobby.home())(trans.newOpponent())
)

View File

@ -73,13 +73,13 @@ object theirs {
)
case Status.Declined =>
div(cls := "follow-up")(
h1(trans.challengeDeclined()),
h1(trans.challenge.challengeDeclined()),
bits.details(c),
a(cls := "button button-fat", href := routes.Lobby.home())(trans.newOpponent())
)
case Status.Accepted =>
div(cls := "follow-up")(
h1(trans.challengeAccepted()),
h1(trans.challenge.challengeAccepted()),
bits.details(c),
a(
id := "challenge-redirect",
@ -91,7 +91,7 @@ object theirs {
)
case Status.Canceled =>
div(cls := "follow-up")(
h1(trans.challengeCanceled()),
h1(trans.challenge.challengeCanceled()),
bits.details(c),
a(cls := "button button-fat", href := routes.Lobby.home())(trans.newOpponent())
)

View File

@ -107,7 +107,7 @@ object studentDashboard {
a(
dataIcon := "U",
cls := List("button button-empty text" -> true, "disabled" -> !online),
title := trans.challengeToPlay.txt(),
title := trans.challenge.challengeToPlay.txt(),
href := online option s"${routes.Lobby.home()}?user=${user.username}#friend"
)(trans.play())
)

View File

@ -32,7 +32,7 @@ object msg {
private val i18nKeys = List(
trans.inbox,
trans.challengeToPlay,
trans.challenge.challengeToPlay,
trans.block,
trans.unblock,
trans.blocked,

View File

@ -22,7 +22,7 @@ object actions {
(myId != userId) ?? frag(
!blocked option frag(
a(
titleOrText(trans.challengeToPlay.txt()),
titleOrText(trans.challenge.challengeToPlay.txt()),
href := s"${routes.Lobby.home()}?user=$userId#friend",
cls := "btn-rack__btn",
dataIcon := "U"

View File

@ -94,7 +94,7 @@ object forms {
)(implicit ctx: Context) =
layout(
"friend",
(if (user.isDefined) trans.challengeToPlay else trans.playWithAFriend)(),
(if (user.isDefined) trans.challenge.challengeToPlay else trans.playWithAFriend)(),
routes.Setup.friend(user map (_.id)),
error.map(e => raw(e.replace("{{user}}", userIdLink(user.map(_.id)).toString)))
)(

View File

@ -73,7 +73,7 @@ object message {
def challengeDenied(msg: String)(implicit ctx: Context) =
apply(
title = trans.challengeToPlay.txt(),
title = trans.challenge.challengeToPlay.txt(),
back = routes.Lobby.home().url.some
)(msg)

View File

@ -80,7 +80,7 @@ object bots {
a(
dataIcon := "U",
cls := List("button button-empty text" -> true),
st.title := trans.challengeToPlay.txt(),
st.title := trans.challenge.challengeToPlay.txt(),
href := s"${routes.Lobby.home()}?user=${u.username}#friend"
)(trans.play())
)

View File

@ -60,7 +60,7 @@ object mini {
a(
dataIcon := "U",
cls := "btn-rack__btn",
title := trans.challengeToPlay.txt(),
title := trans.challenge.challengeToPlay.txt(),
href := s"${routes.Lobby.home()}?user=${u.username}#friend"
)
),

View File

@ -2,7 +2,7 @@ const fs = require('fs').promises;
const parseString = require('xml2js').parseString;
const baseDir = 'translation/source';
const dbs = 'site arena emails learn activity coordinates study clas contact patron coach broadcast streamer tfa settings preferences team perfStat search tourname faq lag swiss puzzle puzzleTheme'.split(' ');
const dbs = 'site arena emails learn activity coordinates study clas contact patron coach broadcast streamer tfa settings preferences team perfStat search tourname faq lag swiss puzzle puzzleTheme challenge'.split(' ');
function ucfirst(s) {
return s.charAt(0).toUpperCase() + s.slice(1);

View File

@ -60,7 +60,7 @@ lazy val i18n = smallModule("i18n",
MessageCompiler(
sourceDir = new File("translation/source"),
destDir = new File("translation/dest"),
dbs = "site arena emails learn activity coordinates study class contact patron coach broadcast streamer tfa settings preferences team perfStat search tourname faq lag swiss puzzle puzzleTheme".split(' ').toList,
dbs = "site arena emails learn activity coordinates study class contact patron coach broadcast streamer tfa settings preferences team perfStat search tourname faq lag swiss puzzle puzzleTheme challenge".split(' ').toList,
compileTo = (sourceManaged in Compile).value
)
}.taskValue

View File

@ -6,6 +6,7 @@ import chess.{ Color, Mode, Speed }
import org.joda.time.DateTime
import lila.game.{ Game, PerfPicker }
import lila.i18n.{ I18nKey, I18nKeys }
import lila.rating.PerfType
import lila.user.User
@ -112,6 +113,13 @@ object Challenge {
def apply(id: Int): Option[Status] = all.find(_.id == id)
}
sealed abstract class DeclineReason(key: I18nKey)
object DeclineReason {
case object Generic extends DeclineReason(I18nKeys.challenge.declineGeneric)
case object Later extends DeclineReason(I18nKeys.challenge.declineLater)
}
case class Rating(int: Int, provisional: Boolean) {
def show = s"$int${if (provisional) "?" else ""}"
}

View File

@ -2,7 +2,7 @@ package lila.challenge
import play.api.i18n.Lang
import lila.i18n.I18nKeys
import lila.i18n.I18nKeys.{ challenge => trans }
import lila.pref.Pref
import lila.rating.PerfType
import lila.relation.{ Block, Follow }
@ -26,13 +26,13 @@ object ChallengeDenied {
def translated(d: ChallengeDenied)(implicit lang: Lang): String =
d.reason match {
case Reason.YouAreAnon => I18nKeys.registerToSendChallenges.txt()
case Reason.YouAreBlocked => I18nKeys.youCannotChallengeX.txt(d.dest.titleUsername)
case Reason.TheyDontAcceptChallenges => I18nKeys.xDoesNotAcceptChallenges.txt(d.dest.titleUsername)
case Reason.YouAreAnon => trans.registerToSendChallenges.txt()
case Reason.YouAreBlocked => trans.youCannotChallengeX.txt(d.dest.titleUsername)
case Reason.TheyDontAcceptChallenges => trans.xDoesNotAcceptChallenges.txt(d.dest.titleUsername)
case Reason.RatingOutsideRange(perf) =>
I18nKeys.yourXRatingIsTooFarFromY.txt(perf.trans, d.dest.titleUsername)
case Reason.RatingIsProvisional(perf) => I18nKeys.cannotChallengeDueToProvisionalXRating.txt(perf.trans)
case Reason.FriendsOnly => I18nKeys.xOnlyAcceptsChallengesFromFriends.txt(d.dest.titleUsername)
trans.yourXRatingIsTooFarFromY.txt(perf.trans, d.dest.titleUsername)
case Reason.RatingIsProvisional(perf) => trans.cannotChallengeDueToProvisionalXRating.txt(perf.trans)
case Reason.FriendsOnly => trans.xOnlyAcceptsChallengesFromFriends.txt(d.dest.titleUsername)
case Reason.BotUltraBullet => "Bots cannot play UltraBullet. Choose a slower time control."
}
}

View File

@ -279,7 +279,6 @@ val `xStartedFollowingY` = new I18nKey("xStartedFollowingY")
val `more` = new I18nKey("more")
val `memberSince` = new I18nKey("memberSince")
val `lastSeenActive` = new I18nKey("lastSeenActive")
val `challengeToPlay` = new I18nKey("challengeToPlay")
val `player` = new I18nKey("player")
val `list` = new I18nKey("list")
val `graph` = new I18nKey("graph")
@ -604,7 +603,6 @@ val `error.max` = new I18nKey("error.max")
val `error.unknown` = new I18nKey("error.unknown")
val `custom` = new I18nKey("custom")
val `notifications` = new I18nKey("notifications")
val `challenges` = new I18nKey("challenges")
val `perfRatingX` = new I18nKey("perfRatingX")
val `practiceWithComputer` = new I18nKey("practiceWithComputer")
val `anotherWasX` = new I18nKey("anotherWasX")
@ -643,12 +641,6 @@ val `advantage` = new I18nKey("advantage")
val `opening` = new I18nKey("opening")
val `middlegame` = new I18nKey("middlegame")
val `endgame` = new I18nKey("endgame")
val `registerToSendChallenges` = new I18nKey("registerToSendChallenges")
val `youCannotChallengeX` = new I18nKey("youCannotChallengeX")
val `xDoesNotAcceptChallenges` = new I18nKey("xDoesNotAcceptChallenges")
val `yourXRatingIsTooFarFromY` = new I18nKey("yourXRatingIsTooFarFromY")
val `cannotChallengeDueToProvisionalXRating` = new I18nKey("cannotChallengeDueToProvisionalXRating")
val `xOnlyAcceptsChallengesFromFriends` = new I18nKey("xOnlyAcceptsChallengesFromFriends")
val `conditionalPremoves` = new I18nKey("conditionalPremoves")
val `addCurrentVariation` = new I18nKey("addCurrentVariation")
val `playVariationToCreateConditionalPremoves` = new I18nKey("playVariationToCreateConditionalPremoves")
@ -698,9 +690,6 @@ val `teamNamedX` = new I18nKey("teamNamedX")
val `youCannotPostYetPlaySomeGames` = new I18nKey("youCannotPostYetPlaySomeGames")
val `subscribe` = new I18nKey("subscribe")
val `unsubscribe` = new I18nKey("unsubscribe")
val `challengeDeclined` = new I18nKey("challengeDeclined")
val `challengeAccepted` = new I18nKey("challengeAccepted")
val `challengeCanceled` = new I18nKey("challengeCanceled")
val `opponentLeftCounter` = new I18nKey("opponentLeftCounter")
val `mateInXHalfMoves` = new I18nKey("mateInXHalfMoves")
val `nextCaptureOrPawnMoveInXHalfMoves` = new I18nKey("nextCaptureOrPawnMoveInXHalfMoves")
@ -1958,4 +1947,20 @@ val `healthyMix` = new I18nKey("puzzleTheme:healthyMix")
val `healthyMixDescription` = new I18nKey("puzzleTheme:healthyMixDescription")
}
object challenge {
val `challenges` = new I18nKey("challenge:challenges")
val `challengeToPlay` = new I18nKey("challenge:challengeToPlay")
val `challengeDeclined` = new I18nKey("challenge:challengeDeclined")
val `challengeAccepted` = new I18nKey("challenge:challengeAccepted")
val `challengeCanceled` = new I18nKey("challenge:challengeCanceled")
val `registerToSendChallenges` = new I18nKey("challenge:registerToSendChallenges")
val `youCannotChallengeX` = new I18nKey("challenge:youCannotChallengeX")
val `xDoesNotAcceptChallenges` = new I18nKey("challenge:xDoesNotAcceptChallenges")
val `yourXRatingIsTooFarFromY` = new I18nKey("challenge:yourXRatingIsTooFarFromY")
val `cannotChallengeDueToProvisionalXRating` = new I18nKey("challenge:cannotChallengeDueToProvisionalXRating")
val `xOnlyAcceptsChallengesFromFriends` = new I18nKey("challenge:xOnlyAcceptsChallengesFromFriends")
val `declineGeneric` = new I18nKey("challenge:declineGeneric")
val `declineLater` = new I18nKey("challenge:declineLater")
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="challenges">Challenges</string>
<string name="challengeToPlay">Challenge to a game</string>
<string name="challengeDeclined">Challenge declined</string>
<string name="challengeAccepted">Challenge accepted!</string>
<string name="challengeCanceled">Challenge canceled.</string>
<string name="registerToSendChallenges">Please register to send challenges.</string>
<string name="youCannotChallengeX">You cannot challenge %s.</string>
<string name="xDoesNotAcceptChallenges">%s does not accept challenges.</string>
<string name="yourXRatingIsTooFarFromY">Your %1$s rating is too far from %2$s.</string>
<string name="cannotChallengeDueToProvisionalXRating">Cannot challenge due to provisional %s rating.</string>
<string name="xOnlyAcceptsChallengesFromFriends">%s only accepts challenges from friends.</string>
<string name="declineGeneric">I'm not accepting challenges at the moment.</string>
<string name="declineLater">I'm not accepting challenges right now, please ask again later.</string>
</resources>

View File

@ -384,7 +384,6 @@ computer analysis, game chat and shareable URL.</string>
<string name="more">More</string>
<string name="memberSince">Member since</string>
<string name="lastSeenActive">Active %s</string>
<string name="challengeToPlay">Challenge to a game</string>
<string name="player">Player</string>
<string name="list">List</string>
<string name="graph">Graph</string>
@ -737,7 +736,6 @@ computer analysis, game chat and shareable URL.</string>
<string name="error.unknown">Error</string>
<string name="custom">Custom</string>
<string name="notifications">Notifications</string>
<string name="challenges">Challenges</string>
<string name="perfRatingX">Rating: %s</string>
<plurals name="nbSecondsToPlayTheFirstMove">
<item quantity="one">%s second to play the first move</item>
@ -784,12 +782,6 @@ computer analysis, game chat and shareable URL.</string>
<string name="opening">Opening</string>
<string name="middlegame">Middlegame</string>
<string name="endgame">Endgame</string>
<string name="registerToSendChallenges">Please register to send challenges.</string>
<string name="youCannotChallengeX">You cannot challenge %s.</string>
<string name="xDoesNotAcceptChallenges">%s does not accept challenges.</string>
<string name="yourXRatingIsTooFarFromY">Your %1$s rating is too far from %2$s.</string>
<string name="cannotChallengeDueToProvisionalXRating">Cannot challenge due to provisional %s rating.</string>
<string name="xOnlyAcceptsChallengesFromFriends">%s only accepts challenges from friends.</string>
<string name="conditionalPremoves">Conditional premoves</string>
<string name="addCurrentVariation">Add current variation</string>
<string name="playVariationToCreateConditionalPremoves">Play a variation to create conditional premoves</string>
@ -843,7 +835,4 @@ computer analysis, game chat and shareable URL.</string>
<string name="youCannotPostYetPlaySomeGames">You can't post in the forums yet. Play some games!</string>
<string name="subscribe">Subscribe</string>
<string name="unsubscribe">Unsubscribe</string>
<string name="challengeDeclined">Challenge declined</string>
<string name="challengeAccepted">Challenge accepted!</string>
<string name="challengeCanceled">Challenge canceled.</string>
</resources>