I saw this question, he explain the method for create a custom messages but not says how do messages with multi languages in the errors. Thanks for your help.
Asked
Active
Viewed 452 times
1 Answers
1
Sails has built-in utility for application internalization based on i18-node package.
Usage is very simple. First you need to configure your locales in config/i18n
folder. Second you need to create translation files under config/locales
folder.
Then you can just use it:
module.exports = {
attributes: {
name: {
type: 'string',
required: true
}
},
validation_messages: {
name: {
required: 'you_have_to_specify_a_name_or_else'
}
}
};
And then in view actually translating:
<p>Validation Error: <%= __('you_have_to_specify_a_name_or_else') %>
If your views are not rendering on backend you can use sails.__()
method for translating directly in the model.

Boris Zagoruiko
- 12,705
- 15
- 47
- 79