我正在寻求翻译 Play framework 2.2 中的验证消息的帮助
我有必填字段: f.e.
@Required(message = "To pole jest wymagane")
public String miesiac;
@Required
public String miejsce;
@Required
public String oddzial;
但我希望在全局范围内传达这样的信息:“To pole jest wymagane”。 我怎样才能实现它? 我是否应该使用 conf/messages.pl 文件进行翻译以润色语言。 请给我一些帮助
最佳答案
是的,您应该使用 conf/messages
文件作为您的默认/主要语言文本,然后使用一个或多个 conf/messages.xx
文件作为您的翻译.
内置 validator 已设置为使用消息文件。例如,Required
validator 将在您的消息中查找键 error.required
并显示该文本。因此,只需在您的消息文件中使用您要使用的文本定义该键即可。
如果您想使用默认值以外的其他内容,则只需使用消息属性指定键(而不是像您的示例中的全文)。
模型类
@Required(message = "my.required.message")
public String miesiac;
session /消息
my.required.message=Hey, you have to type something here.
查看文档了解更多信息:
Externalising messages and internationalization
关于java - playframework 为全局@Required 字段设置自定义消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20471578/