netceteragroup / valdr

A model centric approach to AngularJS form validation
http://netceteragroup.github.io/valdr/
MIT License
153 stars 43 forks source link

support for centralized messages #81

Open hohwille opened 9 years ago

hohwille commented 9 years ago

With I18N support you will typically use message keys and angular-translate. Then you will quickly notice that you start writing

{ 'firstName': { 'required': { 'message': 'key.required' } } 'lastName': { 'required': { 'message': 'key.required' } } ... }

This is not DRY (dont repeat yourself). Instead I would expect that I can define a default message per constraint in a central place. If this is already possible then consider this as a documentation enhancement otherwise a feature request. Thanks!

philippd commented 9 years ago

It is not yet possible, but I agree that such an option would be handy if you don't generate your constraints (for example using valdr-bean-validation) but write them by hand.

emmanuelt88 commented 8 years ago

@hohwille I figure this out by implementing this:

mainApp.config(function (valdrMessageProvider,$translateProvider) {

valdrMessageProvider.setTemplate('

{{ "api.validator." + violation.message | translate }}
');

});

I'm changing the template to include translate and allow the valdr use it instead of having the raw messages.

Hope it helps

hohwille commented 8 years ago

Thanks, meanwhile I also came to the almost same solution. It would be nice to have this in the documentation. However, for the code feel free to close this issue.