Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable i18n translation #58

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,7 +81,6 @@ module.exports = function(sails) {
}
}
},

initialize: function(done) {
var eventsToWaitFor = [];

Expand Down
6 changes: 3 additions & 3 deletions lib/validateCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
148 changes: 79 additions & 69 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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": "[email protected]",
"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"
}
}