I'm new to Node.js/Mongo and I was wondering how I could use i18n with my validation. So far here's what I have
Schema
const UserSchema = new Schema({
language: {
type: String,
enum: ['fr', 'en']
},
email: {
type: String,
default: ''
}
});
Validation
i18n.configure({
locales:['en', 'fr'],
directory:'locales',
defaultLocale: this.language,
cookie: 'locale'
});
UserSchema.path('email').validate(function (email) {
return email.length;
}, i18n.__('Email_is_required'));
I added the configuration of i18n before so I can use it but I know it is not the right way to do it. I tried to use this.language but it is always English by default.
I want to configure i18n with the language sent in my form. Is there a way to do this in the model? Thanks!