在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):rusty1s/mongoose-i18n-localize开源软件地址(OpenSource Url):https://github.com/rusty1s/mongoose-i18n-localize开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):mongoose-i18n-localizemongoose-i18n-localize is a mongoose plugin to support i18n and localization in your mongoose schemas. It seems like mongoose-i18n is not longer supported and I didn't get it to work on my machine, so I decided to write my own version. Usage
Create your schema: var mongoose = require('mongoose');
var mongooseI18n = require('mongoose-i18n-localize');
var schema = new mongoose.Schema({
name: {
type: String,
i18n: true
}
});
schema.plugin(mongooseI18n, {
locales: ['en', 'de']
});
var Model = mongoose.model('Name', schema); This will create a structure like: {
name: {
en: String,
de: String
}
} All validators of mongoose-i18n-localize adds the methods Model.find(function(err, resources) {
var localizedResources = resources.toJSONLocalized('en');
});
//or
Model.find(function(err, resources) {
var localizedResources = Model.schema.methods.toJSONLocalized(resources, 'en');
});
[
{
name: {
en: 'hello',
de: 'hallo',
localized: 'hello'
}
}
] Use If you only want to show only one locale message use the methods
TestsTo run the tests you need a local MongoDB instance available. Run with:
IssuesPlease use the GitHub issue tracker to raise any problems or feature requests. If you would like to submit a pull request with any changes you make, please feel free! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论