I would like to internationalize the form errors returned by Play 2.5 (Scala), when for example the length of field submitted by the user is 2 and the requirement is 3, I get the following error in Firefox in English: "Minimum length is 3". (The project uses French language and other parts of the site display well in French by using the conf/messages.fr
file).
import play.api.data.Form
import play.api.data.Forms.{ mapping, text }
case class NewsData(title: String, rawHTML: String)
object AllForms {
val newsForm: Form[NewsData] = Form {
mapping(
"title" -> text(minLength = 3, maxLength = 255),
"rawHTML" -> text(minLength = 3, maxLength = 19999)
)(NewsData.apply)(NewsData.unapply)
}
}
I have found in the source code of Play that it uses internally the
following message: error.min
in Play 2.5 Validation.scala but putting it in the conf/messages.fr
doesn't work.
What would be the proper way to localize this?
You are using the wrong key.
The key
error.min
corresponds toMust be greater or equal to {0}
. You should useerror.minLength
instead, which corresponds toMinimum length is {0}
.