我使用的形式助手和一個自定義表單模板來渲染我的形式在這樣的遊戲框架:表單錯誤的i18n播放框架
@(lang: Lang)(myForm: Form[MyModel])
@import play.i18n._
@import helper._
@implicitField = @{ FieldConstructor(formTemplate.f) }
@form (action = routes.Application.index()){
@inputText(
field = myForm("username"),
'_label -> Messages.get(lang, "username")
)
}
當模板被稱爲具有不同的值lang
中,標籤以相應的語言顯示。
但是,當提交表格時,錯誤消息總是以主要語言顯示。 (即用於Required
領域,它總是This field is required.
)
至於the answer到this post提到的,我改變了默認的錯誤消息,像這樣在我的語言文件(目前只有2):
messages.en:
username=Username
error.required=This field is required
messages.nl:
username=Gebruikersnaam
error.required=Dit veld is verplicht
如何確保錯誤以正確的語言打印?
我已經嘗試在做我的自定義模板下面,但沒有成功:
@(elements: helper.FieldElements)
<!-- snipped some HTML code -->
<span class="help">
@(elements.infos(elements.args.get('_lang) match {
case Some(language) => language.asInstanceOf[play.api.i18n.Lang]
case None => new Lang("en","uk")
}).mkString(", "))
</span>
若再加上'_lang -> lang
我@inputText
電話。
我習慣於在Java中進行編程,只在Play模板中做了一些Scala。我正在使用Play 2.0.4。
奇怪。放在'messages.nl'中的其他消息是否正確翻譯?在你提到的其他問題中描述的方法完美地工作,你可以在https://play-authenticate.herokuapp.com/signup查看它(手動切換到波蘭語或德語) – biesior
但是當然,我試過這個,它工作,感謝提醒我! – Aerus