fix mobile app form errors translations
This commit is contained in:
parent
1214d7def1
commit
4440ef438d
|
@ -41,7 +41,6 @@ private[controllers] trait LilaController
|
||||||
api = _ => fuccess(Ok(jsonOkBody) as JSON)
|
api = _ => fuccess(Ok(jsonOkBody) as JSON)
|
||||||
)
|
)
|
||||||
|
|
||||||
// implicit def lang(implicit req: RequestHeader) = Env.i18n.pool lang req
|
|
||||||
implicit def lang(implicit ctx: Context) = ctx.lang
|
implicit def lang(implicit ctx: Context) = ctx.lang
|
||||||
|
|
||||||
protected def NoCache(res: Result): Result = res.withHeaders(
|
protected def NoCache(res: Result): Result = res.withHeaders(
|
||||||
|
@ -352,8 +351,21 @@ private[controllers] trait LilaController
|
||||||
else if (HTTPRequest isBot ctx.req) fuccess(NotFound)
|
else if (HTTPRequest isBot ctx.req) fuccess(NotFound)
|
||||||
else result
|
else result
|
||||||
|
|
||||||
protected def errorsAsJson(form: play.api.data.Form[_])(implicit lang: play.api.i18n.Messages) =
|
private val jsonGlobalErrorRenamer = {
|
||||||
lila.common.Form errorsAsJson form
|
import play.api.libs.json._
|
||||||
|
__.json update (
|
||||||
|
(__ \ "global").json copyFrom (__ \ "").json.pick
|
||||||
|
) andThen (__ \ "").json.prune
|
||||||
|
}
|
||||||
|
|
||||||
|
protected def errorsAsJson(form: play.api.data.Form[_])(implicit lang: play.api.i18n.Lang) = {
|
||||||
|
val json = Json.toJson(
|
||||||
|
form.errors.groupBy(_.key).mapValues { errors =>
|
||||||
|
errors.map(e => lila.i18n.Translator.txt.literal(e.message, e.args, lang))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
json validate jsonGlobalErrorRenamer getOrElse json
|
||||||
|
}
|
||||||
|
|
||||||
protected val pgnContentType = "application/x-chess-pgn"
|
protected val pgnContentType = "application/x-chess-pgn"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import org.joda.time.DateTimeZone
|
||||||
import play.api.data.format.Formats._
|
import play.api.data.format.Formats._
|
||||||
import play.api.data.format.Formatter
|
import play.api.data.format.Formatter
|
||||||
import play.api.data.Forms._
|
import play.api.data.Forms._
|
||||||
import play.api.libs.json._
|
|
||||||
|
|
||||||
object Form {
|
object Form {
|
||||||
|
|
||||||
|
@ -39,13 +38,6 @@ object Form {
|
||||||
private def pluralize(pattern: String, nb: Int) =
|
private def pluralize(pattern: String, nb: Int) =
|
||||||
pattern.replace("{s}", (nb != 1).fold("s", ""))
|
pattern.replace("{s}", (nb != 1).fold("s", ""))
|
||||||
|
|
||||||
private val jsonGlobalErrorRenamer = __.json update (
|
|
||||||
(__ \ "global").json copyFrom (__ \ "").json.pick
|
|
||||||
) andThen (__ \ "").json.prune
|
|
||||||
|
|
||||||
def errorsAsJson(form: play.api.data.Form[_])(implicit lang: play.api.i18n.Messages) =
|
|
||||||
form.errorsAsJson validate jsonGlobalErrorRenamer getOrElse form.errorsAsJson
|
|
||||||
|
|
||||||
object formatter {
|
object formatter {
|
||||||
def stringFormatter[A](from: A => String, to: String => A): Formatter[A] = new Formatter[A] {
|
def stringFormatter[A](from: A => String, to: String => A): Formatter[A] = new Formatter[A] {
|
||||||
def bind(key: String, data: Map[String, String]) = stringFormat.bind(key, data).right map to
|
def bind(key: String, data: Map[String, String]) = stringFormat.bind(key, data).right map to
|
||||||
|
|
|
@ -42,7 +42,7 @@ final class DataForm(
|
||||||
regex = """^[^\d].+$""".r,
|
regex = """^[^\d].+$""".r,
|
||||||
error = "usernameStartNoNumber"
|
error = "usernameStartNoNumber"
|
||||||
)
|
)
|
||||||
).verifying("", u => !UserRepo.nameExists(u).awaitSeconds(4))
|
).verifying("usernameAlreadyUsed", u => !UserRepo.nameExists(u).awaitSeconds(4))
|
||||||
.verifying("usernameUnacceptable", u => !LameName(u))
|
.verifying("usernameUnacceptable", u => !LameName(u))
|
||||||
|
|
||||||
val website = Form(mapping(
|
val website = Form(mapping(
|
||||||
|
|
Loading…
Reference in a new issue