playframework为全局@Required字段设置自定义消息

mas*_*y88 5 java forms validation playframework-2.2

我正在寻找帮助翻译Play框架2.2中的Validation messeges

我有需要的字段:fe

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

@Required
public String miejsce;

@Required
public String oddzial;
Run Code Online (Sandbox Code Playgroud)

但是我想在全球范围内传达这样一个信息:"极限开玩笑".我怎么能得到它?我应该使用conf/messagess.pl文件进行翻译.请给我一些帮助

est*_*tic 5

是的,您应该使用该conf/messages文件作为默认/主要语言文本,然后使用一个或多个conf/messages.xx文件进行翻译.

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

如果您想使用默认值之外的其他内容,则只需使用message属性指定键(而不是像示例中那样使用全文).

模型类

@Required(message = "my.required.message")
public String miesiac;
Run Code Online (Sandbox Code Playgroud)

CONF /消息

my.required.message=Hey, you have to type something here.
Run Code Online (Sandbox Code Playgroud)

查看文档以获取更多信息:
外部化消息和国际化