lykmapipo / sails-hook-validation

Custom validation error messages for sails model with i18n support
104 stars 29 forks source link

Use without i18n shows a locale warning #41

Closed boycce closed 8 years ago

boycce commented 8 years ago

Hey, after installing the hook and adding the basic necessities(non i18n) into my model described in the readme, I am getting an error when creating a new user. Using sails 0.11.5 sails-hook-validation 0.4.5

Error

i18n:warn WARN: Locale en couldn't be read - check the context of the call to $__. Using en (default) as current locale +0ms. 

node_modules\sails\node_modules\i18n\i18n.js:503
      return locales[locale][singular];
                            ^
TypeError: Cannot read property 'user.email.unique' of undefined

my model:

attributes: {
  email: {
    type: 'email',
    required: true,
    unique: true
  }
},
validationMessages: {
  email: {
    required: 'An email is required.',
    email: 'Provide a valid email address.',
    unique: 'The email address entered is already being used.'
  }
}
boycce commented 8 years ago

Figured it. Looks like if you are not intending to use i18n, you still need to have the locales folder intact with the correct path inside config/i18n i.e:

localesDirectory: '/config/locales'