diff --git a/README.md b/README.md index 7c1578d..a1945bf 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,44 @@ mongoose-localize ================= A nodejs module to convert mongoose model property to set of localized properties. + +As soon as mongoose_localize has been required... + +```javascript +import mongoose_localize from 'mongoose-localize'; +mongoose_localize.setLocales(['locale1','locale2',...,'localeN']); +``` + +...every attribute of mongoose Scheme containing "localize" attribute set to true... + +```javascript +approverSchema = new mongoose.Schema({ + name: { + type:String, + localize: true + } +}); +``` + +...will be treated as if it would be +```javascript +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. + +```javascript +mongoose_localize.setLocale('locale2'); +```