You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use case would be to allow for easy internationalisation: language detection and passing of messages is handled outside validate, but setMessage should allow for easy passing of locales:
For example, setMessage could be modified as follow (I can create a PR with a complete solution + tests + documentation update if the issue is considered relevant):
FormValidator.prototype.setMessage=function(rule,message){varthat=this;if(!message&&typeofrule==='object'&&!!rule){Object.keys(rule).forEach(function(key){that.messages[key]=rule[key];});}else{that.messages[rule]=message;}// return this for chainingreturnthis;};
And use:
// My object containing all localised copy:vari18n={};i18n.validateJs={required: 'Le champ %s doit être rempli.',matches: 'Le champ %s n\'est pas égal au champ %s.',"default": 'Le champ %s a toujours sa valeur par défaut. Veuillez la changer.',valid_email: 'L\'adresse renseignée doit être une adresse email valide.',};// SetMessage:this.validator.setMessage(i18n.validateJs)
The text was updated successfully, but these errors were encountered:
Personally, I'd be interested in seeing a companion module that is a standalone function, which could take in an internationalization object and then call the right methods on validate.js to achieve the desired effect.
The use case would be to allow for easy internationalisation: language detection and passing of messages is handled outside validate, but setMessage should allow for easy passing of locales:
For example, setMessage could be modified as follow (I can create a PR with a complete solution + tests + documentation update if the issue is considered relevant):
And use:
The text was updated successfully, but these errors were encountered: