Note that there are some explanatory texts on larger screens.

plurals
  1. POTranslate breeze validation messages
    text
    copied!<p>Improving my example on how to use the metadata obtained to create validation rules in knockout (http://stackoverflow.com/questions/13662446/knockout-validation-using-breeze-utility) now I use the validators that breeze inserts into the entities:</p> <pre><code>function addValidationRules(entity) { var entityType = entity.entityType; console.log(entityType); if (entityType) { for (var i = 0; i &lt; entityType.dataProperties.length; i++) { var property = entityType.dataProperties[i]; var propertyName = property.name; var propertyObject = entity[propertyName]; var validators = []; for (var u = 0; u &lt; property.validators.length; u++) { var validator = property.validators[u]; var nValidator = { propertyName: propertyName, validator: function (val, other) { var error = this.innerValidator.validate(val, { displayName: this.propertyName }); this.message = error ? error.errorMessage : ""; return error === null; }, message: "", innerValidator: validator } validators.push(nValidator); } propertyObject.extend({ validation: validators }); } for (var i = 0; i &lt; entityType.foreignKeyProperties.length; i++) { var property = entityType.foreignKeyProperties[i]; var propertyName = property.name; var propertyObject = entity[propertyName]; var validators = []; for (var u = 0; u &lt; property.validators.length; u++) { var validator = property.validators[u]; var nValidator = { propertyName: propertyName, validator: function (val, other) { var error = this.innerValidator.validate(val, { displayName: this.propertyName }); this.message = error ? error.errorMessage : ""; return error === null; }, message: "", innerValidator: validator } validators.push(nValidator); } propertyObject.extend({ validation: validators }); if (!property.isNullable) { //Bussiness Rule: 0 is not allowed for required foreign keys propertyObject.extend({ notEqual: foreignKeyInvalidValue }); } } } }; </code></pre> <p>What I need now is to translate the error messages into my language and I was wondering if it would be possible to include a function to breeze similar to the included in knockout-validation to translate messages:</p> <pre><code>//quick function to override rule messages ko.validation.localize = function (msgTranslations) { var msg, rule; //loop the properties in the object and assign the msg to the rule for (rule in msgTranslations) { if (ko.validation.rules.hasOwnProperty(rule)) { ko.validation.rules[rule].message = msgTranslations[rule]; } } }; //#endregion </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload