forms validation translations - closes #3102
This commit is contained in:
parent
319192bcbc
commit
e1b0ce1397
|
@ -9,31 +9,20 @@ import lila.i18n.I18nKeys
|
|||
|
||||
trait FormHelper { self: I18nHelper =>
|
||||
|
||||
private val errNames = Map(
|
||||
"error.minLength" -> I18nKeys.textIsTooShort,
|
||||
"error.maxLength" -> I18nKeys.textIsTooLong,
|
||||
"captcha.fail" -> I18nKeys.notACheckmate
|
||||
)
|
||||
|
||||
def errMsg(form: Field)(implicit ctx: Context): Html = errMsg(form.errors)
|
||||
|
||||
def errMsg(form: Form[_])(implicit ctx: Context): Html = errMsg(form.errors)
|
||||
|
||||
def errMsg(error: FormError)(implicit ctx: Context): Html = Html {
|
||||
s"""<p class="error">${transKey(error.message, error.args)}</p>"""
|
||||
}
|
||||
|
||||
def errMsg(errors: Seq[FormError])(implicit ctx: Context): Html = Html {
|
||||
errors map { e =>
|
||||
val msg = transKey(e.message, e.args) match {
|
||||
case m if m == e.message => errNames.get(e.message).fold(e.message)(_.txt())
|
||||
case m => m
|
||||
}
|
||||
s"""<p class="error">$msg</p>"""
|
||||
} mkString
|
||||
errors map errMsg mkString
|
||||
}
|
||||
|
||||
def globalError(form: Form[_])(implicit ctx: Context): Option[Html] =
|
||||
form.globalError.map { e =>
|
||||
val msg = transKey(e.message, e.args)
|
||||
Html(s"""<p class="error">$msg</p>""")
|
||||
}
|
||||
form.globalError map errMsg
|
||||
|
||||
val booleanChoices = Seq("true" -> "Yes", "false" -> "No")
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ trait I18nHelper {
|
|||
|
||||
implicit def lang(implicit ctx: UserContext) = ctx.lang
|
||||
|
||||
def transKey(key: String, args: Seq[Any] = Nil)(implicit lang: Lang) =
|
||||
def transKey(key: String, args: Seq[Any] = Nil)(implicit lang: Lang): Html =
|
||||
Translator.html.literal(key, args, lang)
|
||||
|
||||
def i18nJsObjectMessage(keys: Seq[I18nKey])(implicit lang: Lang): JsObject =
|
||||
|
|
|
@ -100,7 +100,7 @@ description = shorten(posts.currentPageResults.headOption.??(_.text).replace("\n
|
|||
<form class="wide" action="@routes.ForumPost.create(categ.slug, topic.slug, posts.currentPage)#reply" method="POST" novalidate>
|
||||
@forum.post.formFields(form("text"), form("author"), topic.some)
|
||||
@base.captcha(form("move"), form("gameId"), captcha)
|
||||
@errMsg(form)
|
||||
@globalError(form)
|
||||
<button type="submit" class="submit button" data-icon="E"> @trans.reply()</button>
|
||||
<a href="@routes.ForumCateg.show(categ.slug)" style="margin-left:20px">@trans.cancel()</a>
|
||||
</form>
|
||||
|
|
|
@ -39,11 +39,12 @@
|
|||
required="required"
|
||||
id="@form("text").id">@form("text").value</textarea>
|
||||
<p class="help">
|
||||
@trans.reportDescriptionHelp()
|
||||
@trans.reportDescriptionHelp()
|
||||
</p>
|
||||
@errMsg(form("text"))
|
||||
</div>
|
||||
@base.captcha(form("move"), form("gameId"), captcha)
|
||||
@globalError(form)
|
||||
<div class="actions">
|
||||
<input class="send button" type="submit" value="@trans.send()" />
|
||||
<a class="cancel" href="@routes.Lobby.home()">@trans.cancel()</a>
|
||||
|
|
|
@ -10,8 +10,8 @@ private[forum] final class DataForm(val captcher: akka.actor.ActorSelection) ext
|
|||
val postMapping = mapping(
|
||||
"text" -> text(minLength = 3),
|
||||
"author" -> optional(text),
|
||||
"gameId" -> nonEmptyText,
|
||||
"move" -> nonEmptyText
|
||||
"gameId" -> text,
|
||||
"move" -> text
|
||||
)(PostData.apply)(PostData.unapply)
|
||||
.verifying(captchaFailMessage, validateCaptcha _)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Generated with bin/trans-dump.js Mon May 29 2017 09:01:56 GMT+0200 (CEST)
|
||||
// Generated with bin/trans-dump.js Mon May 29 2017 11:38:58 GMT+0200 (CEST)
|
||||
package lila.i18n
|
||||
|
||||
// format: OFF
|
||||
|
@ -190,6 +190,7 @@ val `continueFromHere` = new Translated("continueFromHere")
|
|||
val `importGame` = new Translated("importGame")
|
||||
val `thisIsAChessCaptcha` = new Translated("thisIsAChessCaptcha")
|
||||
val `clickOnTheBoardToMakeYourMove` = new Translated("clickOnTheBoardToMakeYourMove")
|
||||
val `captcha.fail` = new Translated("captcha.fail")
|
||||
val `notACheckmate` = new Translated("notACheckmate")
|
||||
val `colorPlaysCheckmateInOne` = new Translated("colorPlaysCheckmateInOne")
|
||||
val `retry` = new Translated("retry")
|
||||
|
@ -213,8 +214,6 @@ val `challengeToPlay` = new Translated("challengeToPlay")
|
|||
val `player` = new Translated("player")
|
||||
val `list` = new Translated("list")
|
||||
val `graph` = new Translated("graph")
|
||||
val `textIsTooShort` = new Translated("textIsTooShort")
|
||||
val `textIsTooLong` = new Translated("textIsTooLong")
|
||||
val `required` = new Translated("required")
|
||||
val `openTournaments` = new Translated("openTournaments")
|
||||
val `duration` = new Translated("duration")
|
||||
|
|
|
@ -10,7 +10,7 @@ private[report] final class DataForm(val captcher: akka.actor.ActorSelection) ex
|
|||
|
||||
val create = Form(mapping(
|
||||
"username" -> nonEmptyText.verifying("Unknown username", { fetchUser(_).isDefined }),
|
||||
"reason" -> nonEmptyText.verifying(Reason.keys contains _),
|
||||
"reason" -> text.verifying("error.required", Reason.keys contains _),
|
||||
"text" -> text(minLength = 5, maxLength = 2000),
|
||||
"gameId" -> text,
|
||||
"move" -> text
|
||||
|
|
|
@ -17,8 +17,8 @@ final class DataForm(
|
|||
case class Empty(gameId: String, move: String)
|
||||
|
||||
val empty = Form(mapping(
|
||||
"gameId" -> nonEmptyText,
|
||||
"move" -> nonEmptyText
|
||||
"gameId" -> text,
|
||||
"move" -> text
|
||||
)(Empty.apply)(_ => None)
|
||||
.verifying(captchaFailMessage, validateCaptcha _))
|
||||
|
||||
|
@ -61,8 +61,8 @@ final class DataForm(
|
|||
|
||||
val passwordReset = Form(mapping(
|
||||
"email" -> anyEmail, // allow unacceptable emails for BC
|
||||
"gameId" -> nonEmptyText,
|
||||
"move" -> nonEmptyText
|
||||
"gameId" -> text,
|
||||
"move" -> text
|
||||
)(PasswordReset.apply)(_ => None)
|
||||
.verifying(captchaFailMessage, validateCaptcha _))
|
||||
|
||||
|
|
|
@ -1142,7 +1142,6 @@ div.checkmateSection div.result {
|
|||
height: 48px;
|
||||
line-height: 48px;
|
||||
vertical-align: middle;
|
||||
padding-left: 54px;
|
||||
font-weight: bold;
|
||||
}
|
||||
div.checkmateSection div.success {
|
||||
|
|
|
@ -297,10 +297,6 @@ div.bar div.pagination {
|
|||
float: right;
|
||||
}
|
||||
|
||||
#lichess_forum div.checkmateCaptcha p.error {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
#lichess_forum div.topic form.mod {
|
||||
float: right;
|
||||
margin-right: 24px;
|
||||
|
|
|
@ -232,6 +232,7 @@
|
|||
</plurals>
|
||||
<string name="thisIsAChessCaptcha">This is a chess CAPTCHA.</string>
|
||||
<string name="clickOnTheBoardToMakeYourMove">Click on the board to make your move, and prove you are human.</string>
|
||||
<string name="captcha.fail">Please solve the chess captcha.</string>
|
||||
<string name="notACheckmate">Not a checkmate</string>
|
||||
<string name="colorPlaysCheckmateInOne">%s plays; checkmate in one move</string>
|
||||
<string name="retry">Retry</string>
|
||||
|
@ -267,8 +268,6 @@
|
|||
<item quantity="one">Less than a minute</item>
|
||||
<item quantity="other">Less than %s minutes</item>
|
||||
</plurals>
|
||||
<string name="textIsTooShort">Text is too short.</string>
|
||||
<string name="textIsTooLong">Text is too long.</string>
|
||||
<string name="required">Required.</string>
|
||||
<string name="openTournaments">Open tournaments</string>
|
||||
<string name="duration">Duration</string>
|
||||
|
|
Loading…
Reference in a new issue