playframework为全局@Required字段设置自定义消息
我正在寻找帮助翻译Play框架2.2中的Validation messeges
我有需要的字段:fe
@Required(message = "To pole jest wymagane") public String miesiac; @Required public String miejsce; @Required public String oddzial;
但是我想在全球范围内传达这样一个信息:“极限开玩笑”。 我怎么能得到它? 我应该使用conf / messagess.pl文件进行翻译。 请给我一些帮助
是的,您应该使用conf/messages
文件作为默认/主要语言文本,然后使用一个或多个conf/messages.xx
文件作为翻译。
已设置内置validation器以使用消息文件。 例如, Required
validator将在您的消息中查找密钥error.required
并显示该文本。 因此,只需使用您要使用的文本在消息文件中定义该键。
如果您想使用默认值之外的其他内容,则只需使用message属性指定键(而不是像示例中那样使用全文)。
模特课
@Required(message = "my.required.message") public String miesiac;
CONF /消息
my.required.message=Hey, you have to type something here.
查看文档以获取更多信息:
外化消息和国际化
所有我发现的东西。 以下是我在conf / messages中的当前自定义消息
error.required=This field is required error.invalid=You need to enter a number constraint.required=Required*