1

我想將Play 2.5(Scala)返回的表單錯誤國際化,例如用戶提交的字段長度爲2,要求爲3,我在Firefox中得到以下錯誤:「最小長度是3「。 (通過使用conf/messages.fr文件,該項目使用法語和該網站的其他部分以法語很好地顯示)。如何國際化Play 2.5中的表單約束?

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) 
    } 
} 

我在遊戲的源代碼,它在內部使用 以下消息發現:error.minPlay 2.5 Validation.scala,但把它在conf/messages.fr不起作用。

什麼是正確的方式來本地化?

回答

1

您正在使用錯誤的密鑰。

密鑰error.min對應於Must be greater or equal to {0}。您應該使用error.minLength來代替,這對應於Minimum length is {0}