diff --git a/index.js b/index.js index d6f5cd5..e2c4782 100644 --- a/index.js +++ b/index.js @@ -61,6 +61,10 @@ module.exports = function(sails) { }); } + if (sails.config.i18n && sails.config.i18n.hookValidation === undefined) { + sails.config.i18n.hookValidation = true; + } + //export hook definition return { //intercent all request and current grab request locale @@ -77,7 +81,6 @@ module.exports = function(sails) { } } }, - initialize: function(done) { var eventsToWaitFor = []; diff --git a/lib/validateCustom.js b/lib/validateCustom.js index 6998346..dfa3db7 100644 --- a/lib/validateCustom.js +++ b/lib/validateCustom.js @@ -68,13 +68,13 @@ module.exports = function(model, invalidAttributes) { var customMessage = phrase; var locale; - if(sails.config.i18n){ + if(sails.config.i18n && sails.config.i18n.hookValidation){ //deduce locale from request else //use default locale locale = sails.config.i18n.requestLocale || - sails.config.i18n.defaultLocale; - + sails.config.i18n.defaultLocale; + if(locale){ //grab custom error //message from config/locales/`locale`.json diff --git a/package.json b/package.json index e1b62b3..2f2b688 100644 --- a/package.json +++ b/package.json @@ -1,75 +1,85 @@ { - "name": "sails-hook-validation", - "version": "0.4.7", - "description": "Custom validation error messages for sails model with i18n support", - "main": "index.js", - "sails": { - "isHook": true + "name": "sails-hook-validation", + "version": "0.4.7", + "description": "Custom validation error messages for sails model with i18n support", + "main": "index.js", + "sails": { + "isHook": true + }, + "scripts": { + "pretest": "npm link && npm link sails-hook-validation", + "test": "grunt test" + }, + "repository": { + "type": "git", + "url": "https://github.com/lykmapipo/sails-hook-validation.git" + }, + "keywords": [ + "sails", + "sails-hook", + "model", + "validator", + "validation", + "validate", + "custom", + "messages", + "define", + "database", + "exceptions", + "constraints", + "i18n", + "internationalization", + "hook", + "plugin", + "error", + "module" + ], + "author": { + "name": "lykmapipo", + "email": "lallyelias87@gmail.com", + "url": "https://github.com/lykmapipo" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/lykmapipo/sails-hook-validation/issues" + }, + "homepage": "https://github.com/lykmapipo/sails-hook-validation", + "contributors": [ + { + "name": "lykmapipo", + "github": "https://github.com/lykmapipo" }, - "scripts": { - "pretest": "npm link && npm link sails-hook-validation", - "test": "grunt test" + { + "name": "isery", + "github": "https://github.com/isery" }, - "repository": { - "type": "git", - "url": "https://github.com/lykmapipo/sails-hook-validation.git" + { + "name": "Alaneor", + "github": "https://github.com/Alaneor" }, - "keywords": [ - "sails", - "sails-hook", - "model", - "validator", - "validation", - "validate", - "custom", - "messages", - "define", - "database", - "exceptions", - "constraints", - "i18n", - "internationalization", - "hook", - "plugin", - "error", - "module" - ], - "author": { - "name": "lykmapipo", - "email": "lallyelias87@gmail.com", - "url": "https://github.com/lykmapipo" - }, - "license": "MIT", - "bugs": { - "url": "https://github.com/lykmapipo/sails-hook-validation/issues" - }, - "homepage": "https://github.com/lykmapipo/sails-hook-validation", - "contributors": [{ - "name": "lykmapipo", - "github": "https://github.com/lykmapipo" - }, { - "name": "isery", - "github": "https://github.com/isery" - }, { - "name": "Alaneor", - "github": "https://github.com/Alaneor" - }, { - "name": "VMBindraban", - "github": "https://github.com/VMBindraban" - }], - "devDependencies": { - "chai": "^2.3.0", - "faker": "^2.1.5", - "grunt": "^0.4.5", - "grunt-contrib-jshint": "^0.11.3", - "grunt-mocha-test": "^0.12.7", - "jshint-stylish": "^1.0.2", - "mocha": "^2.4.5", - "sails": "^0.11.2", - "sails-disk": "^0.10.8", - "supertest": "^1.1.0" - }, - "dependencies": { - "waterline": "^0.10.31" + { + "name": "VMBindraban", + "github": "https://github.com/VMBindraban" } + ], + "devDependencies": { + "chai": "^2.3.0", + "faker": "^2.1.5", + "grunt": "^0.4.5", + "grunt-contrib-jshint": "^0.11.3", + "grunt-mocha-test": "^0.12.7", + "jshint-stylish": "^1.0.2", + "mocha": "^2.4.5", + "sails": "^0.11.2", + "sails-disk": "^0.10.8", + "supertest": "^1.1.0" + }, + "dependencies": { + "anchor": "^1.3.0", + "async": "^2.6.1", + "bluebird": "^3.5.3", + "lodash": "^4.17.11", + "prompt": "^1.0.0", + "waterline": "^0.10.31" + } }