This plugin only comes with English messages to keep things small, but it was built with flexible message generation in mind.
The English messages file is an example on how you would structure those messages.
Then you may want to update the validator dictionary, which should happen once in your app startup. still you may update them whenever you want in any point of your app, review the custom messages here.
Seeing 'first_name' in your error messages can't be very good for your user experience, this plugin offer a couple of solutions:
You can use the data-as
attribute on your field and give it a better name for your users, it would look like this:
data-as
value instead of the actual field name. this is also the same for binding expressions.
While this is very useful for simple setups and displaying localized names, you might want to check the approach below.
All validators have access to a simple dictionary that is shared between all of them, this dictionary contains localized error messages and attributes, if the validator finds a localized attribute name for that field it will be used instead of the field name.
Pretty much like data-as
but data-as
takes priorty if both are found.
Here is a little code example on how would you add support for your localized messages and attributes. Note that this is the entry point of your application.
setLocale
method on the validator instance.
And you can also switch the language for all future validators (not created yet) via the setDefaultLocale
static method on the Validator class.
In the dist/locale
directory of this plugin, is a collection of localized files, mainly the English and The Arabic languages.
If you can't find your locale, you could help this plugin by contributing a localized version to the repo. I will happily accept it.