全球范围内为@Required字段设置playframework定制消息 [英] playframework setting custom message for @Required field globally

查看:95
本文介绍了全球范围内为@Required字段设置playframework定制消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关在Play框架2.2中翻译Validation信息的帮助

我有一些必填字段:

@Required(message = "To pole jest wymagane")
public String miesiac;

@Required
public String miejsce;

@Required
public String oddzial;

但是我会收到以下消息:全球范围内的"To jest wymagane". 我该如何实现? 我应该使用conf/messagess.pl文件进行翻译还是要波兰语. 请给我一些帮助

解决方案

是的,您应该将conf/messages文件用于默认/主要语言文本,然后将一个或多个conf/messages.xx文件用于翻译. /p>

已经设置了内置验证器以使用消息文件.例如,Required验证器将在消息中查找键error.required并显示该文本.因此,只需在消息文件中使用要使用的文本定义该键即可.

如果要使用默认值以外的其他值,则只需使用message属性(而不是示例中的全文)指定键即可.

模型类

@Required(message = "my.required.message")
public String miesiac;

conf/messages

my.required.message=Hey, you have to type something here.


有关更多信息,请参阅文档:
外部化消息和国际化

I am looking for help with translating Validation messeges in Play framework 2.2

I have fields that are required: f.e.

@Required(message = "To pole jest wymagane")
public String miesiac;

@Required
public String miejsce;

@Required
public String oddzial;

But I would to have this message: "To pole jest wymagane" globally. How can I achive it? Should I use conf/messagess.pl file for translation To polish language. Please give me some help

解决方案

Yes, you should use the conf/messages file for your default/primary language text and then one or more of the conf/messages.xx files for your translations.

The built-in validators are already setup to use the messages files. For example, the Required validator will look for the key error.required in your messages and display that text. So just define that key in your message files with the text you want to use.

If you wanted to use something other than the default then just specify the key with the message attribute (instead of the full text like in your example).

Model class

@Required(message = "my.required.message")
public String miesiac;

conf/messages

my.required.message=Hey, you have to type something here.


Take a look at the documentation for more info:
Externalising messages and internationalization

这篇关于全球范围内为@Required字段设置playframework定制消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆