Rails 4:非ActiveRecord对象上的ActiveRecord样式的I18n吗?

Qqw*_*qwy 4 activerecord ruby-on-rails rails-i18n

我有一个普通的老式Ruby类(PORO),其行为很像ActiveRecord模型,尽管它没有持久化到数据库中。

为了使国际化(I18n)尽可能轻松,我也想在此PORO上使用SomeModel.model_name.humanSomeModel.human_attribute_name(:attribute)方法。

我需要包括什么模块才能在PORO上包含上述方法?

inf*_*sed 5

使用ActiveModel::Translation模块扩展您的课程:

class Widget
  extend ActiveModel::Translation
end

Widget.model_name.human
=> "Widget"

Widget.human_attribute_name :my_attribute
=> "My attribute"
Run Code Online (Sandbox Code Playgroud)