问题
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
回答1:
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
回答2:
All what I found out. Here are my current custom messages in conf/messages
error.required=This field is required
error.invalid=You need to enter a number
constraint.required=Required*
来源:https://stackoverflow.com/questions/20471578/playframework-setting-custom-message-for-required-field-globally