使用mongoid在rails中转换模型属性的方法是什么?

Mic*_*ski 10 translation ruby-on-rails mongodb mongoid ruby-on-rails-3

我有mongoid和模型翻译的问题.当我尝试在我的模型上使用mongoDB时,我不知道要翻译属性和模型名称.它通常在*.yml文件中,但在这个时候这不起作用.有任何想法吗?

小智 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"
        #...
Run Code Online (Sandbox Code Playgroud)

从这里


小智 7

在yml文件中尝试这个(在我的例子中是config/locales/pt-BR.yml):

 activemodel:
    attributes:
      [model_name]:
        [attribute1]: "[translation1]"
        [attribute2]: "[translation2]"
        [attribute3]: "[translation3]"
Run Code Online (Sandbox Code Playgroud)

为我工作,使用mongoid 2.0.0.beta.17和rails 3.0.0

  • 如何翻译模型本身的名称? (2认同)