【问题标题】:How to internationalize form constraints in Play 2.5?如何在 Play 2.5 中国际化表单约束?
【发布时间】:2016-12-28 15:40:22
【问题描述】:

我想将 Play 2.5 (Scala) 返回的表单错误国际化,例如当用户提交的字段长度为 2 并且要求为 3 时,我在 Firefox 中收到以下英文错误:“Minimum长度为 3"。 (该项目使用法语,站点的其他部分通过使用conf/messages.fr 文件以法语很好地显示)。

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

我在 Play 的源代码中发现它在内部使用 以下消息:error.min in Play 2.5 Validation.scala 但将其放入 conf/messages.fr 不起作用。

本地化的正确方法是什么?

【问题讨论】:

    标签: scala playframework internationalization playframework-2.5


    【解决方案1】:

    您使用了错误的密钥。

    密钥error.min 对应于Must be greater or equal to {0}。您应该改用error.minLength,它对应于Minimum length is {0}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多