Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame authored Oct 23, 2016
1 parent ad2fc9f commit e149123
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```

0 comments on commit e149123

Please sign in to comment.