我对mongoid和模型翻译有疑问。当我尝试在我的模型上使用mongoDB时,我不知道要翻译属性和模型名称。它通常在* .yml文件中,但在这个时候这不起作用。有什么想法吗?
答案 0 :(得分:14)
变体与“activemodel”对我不起作用。但
这个变体对我有用:
en:
mongoid:
errors:
models:
user:
attributes:
email:
blank: "You have to give me your e-mail address"
not_found: "e-mail address not found in list of members"
#...
attributes:
user:
email: "Email address"
name: "Your nickname"
#...
答案 1 :(得分:7)
在yml文件中尝试这个(在我的例子中是config / locales / pt-BR.yml):
activemodel:
attributes:
[model_name]:
[attribute1]: "[translation1]"
[attribute2]: "[translation2]"
[attribute3]: "[translation3]"
为我工作,使用mongoid 2.0.0.beta.17和rails 3.0.0
答案 2 :(得分:0)
像这样使用:
mongoid:
attributes:
article:
title: "Article title"
答案 3 :(得分:0)
如果您使用引擎,您可以命名模型
en:
activerecord:
models:
'my_engine/mymodel':
one: TranslatedMyModel
other: TranslatedMyModels
attributes:
'my_engine/mymodel':
myattribute: translated attribute
或者如果您使用 mongoid
en:
mongoid:
models:
'my_engine/mymodel':
one: TranslatedMyModel
other: TranslatedMyModels
attributes:
'my_engine/mymodel':
myattribute: translated attribute
我使用this问题的评论解决了这个问题。