我如何在 ActiveRecord 之外使用 ActiveModel::Validations 的 I18N 翻译?

How can I use I18N translations with ActiveModel::Validations outside of ActiveRecord?

Rails 指南提供的 I18n 范围特定于 ActiveRecord 对象中 ActiveModel::Validations 的使用。例如:

en:
  activerecord:
    errors:
      models:
        some_model:
          attributes:
            name:
              blank: "Please enter your full legal name."

以这种方式使用 ActiveModel::Validations 时,这将不起作用:

class SomeModel
  include ActiveModel::Validations
  validates :name, presence: true
end

而是使用框架默认的“不能为空”。

如何解决?

activemodel 代替 activerecord 解决了这个问题,并允许所有后续范围工作。示例:

en:
  activemodel: # <---
    errors:
      models:
        message:
          attributes:
            name:
              blank: "Please enter your name."