A nodejs module to convert mongoose model property to set of localized properties.
As soon as mongoose_localize has been required...
import mongoose_localize from 'mongoose-localize';
mongoose_localize.setLocales(['locale1','locale2',...,'localeN']);
...every attribute of mongoose Scheme containing "localize" attribute set to true...
approverSchema = new mongoose.Schema({
name: {
type:String,
localize: true
}
});
...will be treated as if it would be
approverSchema = new mongoose.Schema({
name: {
locale1: {type:String},
locale2: {type:String},
...
localeN: {type:String},
}
});
approverSchema.virtual('localized.name').get(function () {
// return name in the current locale
...
});
The "localize" attribute will be removed from source Scheme. It's nor a bug neither a feature, it is "by design".
While the module must be required and setLocales must be called before the first Schema added the current locale may be set and changed in any moment.
mongoose_localize.setLocale('locale2');