File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,44 @@ mongoose-localize
2
2
=================
3
3
4
4
A nodejs module to convert mongoose model property to set of localized properties.
5
+
6
+ As soon as mongoose_localize has been required...
7
+
8
+ ``` javascript
9
+ import mongoose_localize from ' mongoose-localize' ;
10
+ mongoose_localize .setLocales ([' locale1' ,' locale2' ,... ,' localeN' ]);
11
+ ```
12
+
13
+ ...every attribute of mongoose Scheme containing "localize" attribute set to true...
14
+
15
+ ``` javascript
16
+ approverSchema = new mongoose.Schema ({
17
+ name: {
18
+ type: String ,
19
+ localize: true
20
+ }
21
+ });
22
+ ```
23
+
24
+ ...will be treated as if it would be
25
+ ``` javascript
26
+ approverSchema = new mongoose.Schema ({
27
+ name: {
28
+ locale1: {type: String },
29
+ locale2: {type: String },
30
+ ...
31
+ localeN: {type: String },
32
+ }
33
+ });
34
+ approverSchema .virtual (' localized.name' ).get (function () {
35
+ // return name in the current locale
36
+ ...
37
+ });
38
+ ```
39
+ The "localize" attribute will be removed from source Scheme. It's nor a bug neither a feature, it is "by design".
40
+
41
+ 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.
42
+
43
+ ``` javascript
44
+ mongoose_localize .setLocale (' locale2' );
45
+ ```
You can’t perform that action at this time.
0 commit comments