Node.js MongoDB与i18n
我想使用MongooseODM在MongoDB中建模一个国际化的集合。它只需要存储三种语言的字符串(名称) 您将如何对该模式进行建模?我想到过这样的事情:Node.js MongoDB与i18n,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我想使用MongooseODM在MongoDB中建模一个国际化的集合。它只需要存储三种语言的字符串(名称) 您将如何对该模式进行建模?我想到过这样的事情: _id: ObjectID(...), name: { en: 'Ten', es: 'Diez', fr: 'Dix' } 有没有办法使用枚举来指示语言代码,而不是将它们硬编码到Mongoose模式中?如果您能提供一些关于如何在MongoDB中实现收藏国际化的一般性建
_id: ObjectID(...),
name: {
en: 'Ten',
es: 'Diez',
fr: 'Dix'
}
有没有办法使用枚举来指示语言代码,而不是将它们硬编码到Mongoose模式中?如果您能提供一些关于如何在MongoDB中实现收藏国际化的一般性建议,我将不胜感激
更新:
我将最终使用mongoose-i18n插件:您可以遵循以下模式:
_id: ObjectID(...),
name:[
'Ten',
'Diez',
'Dix'
]
与您提到的模式相比,使用这种模式的优点是查询会稍微容易一些,您可以通过引用数组中的位置来访问特定语言中的字段。向数组中添加较新的entires也会更容易。唯一的缺点是必须遵循特定的顺序 也许这对你有帮助 在模型中:
first_name: {
type: String,
required: [true, "models.subscriber.required"]
},
在你看来
{{#each errors }}
<p class="mb-0 ">{{ translate this}}</p>
{{/each}}
"models": {
"subscriber": {
"required": "The first name is required",
}
}