2012-09-25 50 views
1

我想翻译由views.html.helpers._输入生成的标记的默认约束和错误消息。我在文档中找不到它,并且已经开始浏览代码,但如果有人比我快,请回答并获得奖励。对于现场信息和错误,i18n消息ID是什么?

下面是示例模板代码:

@inputText(regForm("Login"), 'id-> "username", 'placeholder -> "Login", 'required -> "yes", 'autofocus -> "yes") 

这里是生成的HTML:

<div id="username_field" class="error clearfix"> 
<div class="input"> 

<input type="text" id="username" name="Login" value="" id="username" placeholder="Login" required="yes" autofocus="yes"> 

    <span class="help-inline">This field is required</span> 
    <span class="help-block">Required</span> 
</div> 

我想翻译出现在最后两个跨度文本。

编辑: 我已经知道翻译是如何工作的from the documentation。没有说明的是,在没有满足字段约束的情况下显示的消息(错误消息)和一般信息的默认消息ID。

回答

3

您必须覆盖source messages file中您自己的messages.xy文件中的标签。

也看看other answer前段时间,如果默认语言的文件不是lang扩展名,则会出现问题。 AFAIK在答案后被修复了,但是如果你检查它并确认评论中的当前状态,它会很酷。

+0

好吧,好的:我的错。只阅读你回答的问题是正确的。但是我特意询问了消息ID,并且我找到了它。看到我的答案。 – Rajish

0

浏览代码我发现它在哪里被记录。特征文档中简要提及了密钥。你必须展开约束生成器的定义来读取它。 forms handling documentation中涵盖了如何使用约束。但没有覆盖另一种方式存在 - 通过使用输入属性喜欢这里:

@inputText(regForm("Login"), 'id-> "username", 'placeholder -> "Login", 'required -> "yes", 'autofocus -> "yes") 

这里是在/Play20/framework/src/play/src/main/scala/play/api/data/validation/Validation.scala(主分支)来实现的ID:

  • nonEmpty(即与'required场属性)
    • 的相关信息:constraint.required
    • 错误:error.required
  • min(即,具有'min属性的字段;用一个参数的消息)
    • 的相关信息:constraint.min(minValue)
    • 错误:error.min(minValue)
  • max(即'max属性的字段;用一个参数的消息)
    • 的相关信息:constraint.max(maxValue)
    • 错误:error.max(maxValue)
  • minLength(即与'minLength属性的字段)
    • 的相关信息:constraint.minLength(length)
    • 错误:error.minLength(length)
  • maxLength(即一个字段与'maxLength属性)
    • 的相关信息:constraint.maxLength(length)
    • 错误:error.maxLength(length)
  • pattern(即与'regex属性的字段)
    • 的相关信息:constraint.pattern(regex)
    • 错误:error.pattern(regex)

上述HTML5中引入的属性,所以他们不会被所有的浏览器进行处理,但框架验证将处理它。