我正在尝试国际化我的Booking
模型的属性
From my first .yml:
attributes: &attributes
booking:
first_name: 'Prénom'
last_name: 'Nom'
email: "Email"
phone: 'Téléphone'
activemodel:
errors:
<<: *errors
attributes:
<<: *attributes
当我生成一个rails控制台:
2.0.0p0 :011 > I18n.t(:activemodel)[:attributes][:booking]
=> {:first_name=>"Prénom", :last_name=>"Nom", :email=>"Email", :phone=>"Téléphone"}
但:
2.0.0p0 :013 > Booking.human_attribute_name('first_name')
=> "First name"
然而,在我的web服务器上,错误仍然是英语+法语,例如:
"名字doit être rempli(e)"
我错过了什么?我使用的是mongoid, ruby 2.0.0和rails 3.2.11。
注意,我使用model.errors.full_messages
来检索错误消息。
修复:
mongoid:
attributes:
<<: *attributes
似乎即使Mongoid::Document
包括ActiveModel::Validation
,您也必须为翻译定义一个单独的键