如何处理ActiveModel的翻译?

Bac*_*cko 15 ruby ruby-on-rails internationalization ruby-on-rails-3 ruby-on-rails-3.1

我正在使用Rails 3.1.1,我想正确翻译错误消息ActiveModel.我不知道是否覆盖i18n_scope是解决问题的正确方法(或者有其他方法),但官方文档说:

i18n_scope()

返回类的i18n_scope.如果要自定义查找,请覆盖.

...... 我该如何过度加重i18n_scope

这时我得到以下"警告":

# Note the 'activemodel' part
translation missing: de.activemodel.errors.models.my_class.attributes.message.blank

# I would like to "map" translations to 'de.activerecord.errors.messages.blank'
# as made for all other ActiveRecord classes in my application
Run Code Online (Sandbox Code Playgroud)

我的ActiveModel班级如下:

class MyClass
  include ActiveModel::Conversion
  include ActiveModel::Validations
  include ActiveModel::Dirty
  extend  ActiveModel::Naming
  extend  ActiveModel::Translation

  validates :name, :presence => true

  ...
end
Run Code Online (Sandbox Code Playgroud)

cly*_*yfe 11

它应该是一个类方法,类似于AR代码:

class MyClass
  include ActiveModel ...
  class << self
    def i18n_scope
      :activerecord
    end
  end
end
Run Code Online (Sandbox Code Playgroud)