Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

playframework setting custom message for @Required field globally

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

like image 538
masterdany88 Avatar asked Dec 09 '13 13:12

masterdany88


2 Answers

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

like image 95
estmatic Avatar answered Oct 03 '22 07:10

estmatic


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*
like image 24
masterdany88 Avatar answered Oct 03 '22 07:10

masterdany88