diff --git a/package.json b/package.json index c5fb34a36..c0ee18cc0 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ }, "dependencies": { "ajv": "3.4.0", + "ajv-i18n": "1.0.0", "brace": "0.7.0" }, "devDependencies": { diff --git a/src/js/JSONEditor.js b/src/js/JSONEditor.js index 037df66c4..be873b186 100644 --- a/src/js/JSONEditor.js +++ b/src/js/JSONEditor.js @@ -77,7 +77,7 @@ function JSONEditor (container, options, json) { 'ace', 'theme', 'ajv', 'schema', 'onChange', 'onEditable', 'onError', 'onModeChange', - 'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation' + 'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'lang' ]; Object.keys(options).forEach(function (option) { diff --git a/src/js/textmode.js b/src/js/textmode.js index 452b5fff9..8cbf89ef9 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -6,6 +6,7 @@ catch (err) { // failed to load ace, no problem, we will fall back to plain text } +var localize = require('ajv-i18n'); var modeswitcher = require('./modeswitcher'); var util = require('./util'); @@ -409,6 +410,7 @@ textmode.validate = function () { if (doValidate && this.validateSchema) { var valid = this.validateSchema(json); if (!valid) { + this._translate(this.validateSchema.errors); errors = this.validateSchema.errors.map(function (error) { return util.improveSchemaError(error); }); @@ -457,6 +459,13 @@ textmode.validate = function () { } }; +textmode._translate = function(errors) { + var fn = localize[this.options.lang]; + if (fn !== undefined && fn !== null) { + fn(errors); + } +}; + // define modes module.exports = [ { diff --git a/src/js/treemode.js b/src/js/treemode.js index 3f759fa1d..beca2faca 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -1,3 +1,4 @@ +var localize = require('ajv-i18n') var Highlighter = require('./Highlighter'); var History = require('./History'); var SearchBox = require('./SearchBox'); @@ -373,6 +374,7 @@ treemode.validate = function () { var valid = this.validateSchema(root.getValue()); if (!valid) { // apply all new errors + this._translate(this.validateSchema.errors); schemaErrors = this.validateSchema.errors .map(function (error) { return util.improveSchemaError(error); @@ -417,6 +419,13 @@ treemode.validate = function () { }); }; +treemode._translate = function(errors) { + var fn = localize[this.options.lang]; + if (fn !== undefined && fn !== null) { + fn(errors); + } +}; + /** * Start autoscrolling when given mouse position is above the top of the * editor contents, or below the bottom.