ruby-on-rails – 如何处理ActiveModel的翻译?
发布时间:2020-12-16 20:08:47 所属栏目:百科 来源:网络整理
导读:我正在使用Rails 3.1.1,我想正确翻译ActiveModel的错误消息.我不知道如果覆盖i18n_scope是解决我的问题的正确方法(或者有其他方法),但是 official documentation说: i18n_scope() Returns the i18n_scope for the class. Overwrite if you want custom look
我正在使用Rails 3.1.1,我想正确翻译ActiveModel的错误消息.我不知道如果覆盖i18n_scope是解决我的问题的正确方法(或者有其他方法),但是
official documentation说:
…我应该如何超越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 我的ActiveModel类如下所示: class MyClass include ActiveModel::Conversion include ActiveModel::Validations include ActiveModel::Dirty extend ActiveModel::Naming extend ActiveModel::Translation validates :name,:presence => true ... end 解决方法
它应该是一个类的方法,类比与
AR code:
class MyClass include ActiveModel ... class << self def i18n_scope :activerecord end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |