How can I overwrite the NotBlank
constraint message This value should not be blank
globally throughout the Symfony 2.1 application?
I've tried with validators.en.yml
files, but this works only if I set for every NotBlank constraint in my validation.yml
files to a constant like not.blank.field
- but is too much to modify.
To replace This value should not be blank
message showing up when the NotBlank
constraint is triggered at your application level, simply create the right translation file in the right place.
To make it simple, your locale seems to be English (en), so create the file app/Resources/translations/validators.en.yml
and write the following line in it:
# app/Resources/translations/validators.en.yml
This value should not be blank.: Y U NO SET THE VALUE?!
The first part has to match exactly the message you want to translate (in your case This value should not be blank.
).
If you have a custom files/folders hierarchy, simply create the file under <kernel root directory>/Resources/translations
.
If you want to have the same behavior for another language (french for example), simply create the corresponding file in the same folder:
# app/Resources/translations/validators.fr.yml
This value should not be blank.: La valeur doit etre specifiee.
Do not forget to clear your cache after adding the new file!
Why does it work? Because Symfony2 priorities the translation files by locations: http://symfony.com/doc/current/book/translation.html#translation-locations-and-naming-conventions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With