2

I am trying to internationalize the attributes of my Booking model

From my fr.yml :

  attributes: &attributes
    booking:
      first_name: 'Prénom'
      last_name: 'Nom'
      email: "Email"
      phone: 'Téléphone'

  activemodel:
    errors:
      <<: *errors
    attributes:
      <<: *attributes

When I spawn a rails console :

2.0.0p0 :011 > I18n.t(:activemodel)[:attributes][:booking]
 => {:first_name=>"Prénom", :last_name=>"Nom", :email=>"Email", :phone=>"Téléphone"}

but :

2.0.0p0 :013 > Booking.human_attribute_name('first_name')
 => "First name"

However, on my web server, the errors are still english + french, such as :

"First name doit être rempli(e)"

What am I missing ? I'm using mongoid, ruby 2.0.0 and rails 3.2.11.

Note that I am using model.errors.full_messages to retrieve the error messages.

Intrepidd
  • 19,772
  • 6
  • 55
  • 63

1 Answers1

1

Fixed it :

mongoid:
  attributes:
    <<: *attributes

It seems that even if Mongoid::Document includes ActiveModel::Validation, you have to define a separate key for the translation.

Intrepidd
  • 19,772
  • 6
  • 55
  • 63