如何在Play Framework 2.2.1中声明可本地化的表单验证消息,包括需要参数的消息?可本地化的表单验证消息
例如,考虑到这些本地化的消息在conf/messages
:
password.tooShort="Password needs at least {0} characters."
password.doNotMatch="Passwords don't match."
和一个表单定义是这样的:
val minLength = 8
val changePasswordForm = Form (
Password ->
tuple(
Password1 -> nonEmptyText.verifying("password.tooShort", p => p.length() >= minLength),
Password2 -> nonEmptyText
).verifying("password.doNotMatch", passwords => passwords._1 == passwords._2)
)
如何能在第一场(密码1)确认消息中声明一种适当的参数将被使用的方式(minLength)?
的形式定义调用verifying
,只接受字符串的邮件不带参数:
def verifying(error: => String, constraint: (T => Boolean)): Mapping[T] = {
verifying(Constraint { t: T =>
if (constraint(t)) Valid else Invalid(Seq(ValidationError(error)))
})
}
此外,格式定义过程中调用消息()不起作用,因为它会导致默认语言被使用,而不是的每个请求的语言。