1.0.10 • Published 10 years ago

mongoose-localize v1.0.10

Weekly downloads
25
License
ISC
Repository
github
Last release
10 years ago

mongoose-localize

A nodejs module to convert mongoose model property to set of localized properties.

As soon as mongoose_localize has been required with CommonJS ...

var
	mongoose = require('mongoose'),
	localize = require('mongoose-localize');

or imported and initialized with ES6 syntax

import mongoose from 'mongoose';
import mongoose_localize from 'mongoose-localize';
mongoose_localize.localize(mongoose,[currentLocale[,locales]]);

or with another (better) ES6 syntax

import mongoose from 'mongoose';
import {localize as mongoose_localize} from 'mongoose-localize';
mongoose_localize(mongoose,'ru',['en','ru']);

...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('name._').get(function () {
// return name in the current locale
  ...
}).set(function (v) {
// set name of the current locale to v
  ...
})
;

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.setCurrenLocale('locale2');

Locales and current locales may be retrieved with

mongoose_localize.locales();
mongoose_localize.currentLocale();
1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.1.0

10 years ago

0.0.7

10 years ago

0.0.6

12 years ago

0.0.5

12 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago