views:

1483

answers:

3

I am upgrading an application a rails application to 2.3.2 and I am finding that I can't display the default validation error messages for ActiveRecord because I don't have a translation file for it.

This is the error that is reported:

translation missing: en-US, activerecord, errors, template, header
translation missing: en-US, activerecord, errors, template, body
Email translation missing: en-US, activerecord, errors, models, user, attributes, email, taken

Does anyone know where I can find a default English translation file that would include all the strings that the validations might use?

A: 

Did you run rake:rails:update after you upgraded?

John Topley
Yes, but it doesn't add the config/locales directory that exists if you create a brand new rails project using 2.3.2
Kyle Boon
And that directory doesn't have the full AR translation files anyway.
Kyle Boon
+2  A: 

This happened because my language setting was 'en-US' and not 'en'. There are translation files under activerecord/lib/locale. I copied these translations into a new file en_US.yml.

"en-US": 
  activerecord:
    errors: 
        template: 
            body: There were problems with the following fields
            header: 
                one: 1 error prohibited this {{model}} from being saved
                other: "{{count}} errors prohibited this {{model}} from being saved"  
        messages:
            inclusion: "is not included in the list"
            exclusion: "is reserved"
            invalid: "is invalid"
            confirmation: "doesn't match confirmation"
            accepted: "must be accepted"
            empty: "can't be empty"
            blank: "can't be blank"
            too_long: "is too long (maximum is {{count}} characters)"
            too_short: "is too short (minimum is {{count}} characters)"
            wrong_length: "is the wrong length (should be {{count}} characters)"
            taken: "has already been taken"
            not_a_number: "is not a number"
            greater_than: "must be greater than {{count}}"
            greater_than_or_equal_to: "must be greater than or equal to {{count}}"
            equal_to: "must be equal to {{count}}"
            less_than: "must be less than {{count}}"
            less_than_or_equal_to: "must be less than or equal to {{count}}"
            odd: "must be odd"
            even: "must be even"

Then I just added my custom strings after these.

Kyle Boon
A: 

FYI, if you are including these in the old style hash format, use this;

:activerecord => {
  :errors => {
      :template => {
          :body => 'There were problems with the following fields',
          :header => { 
              :one => '1 error prohibited this {{model}} from being saved',
              :other => "{{count}} errors prohibited this {{model}} from being saved"
          }
      },
      :messages => {
          :inclusion => "is not included in the list",
          :exclusion => "is reserved",
          :invalid => "is invalid",
          :confirmation => "doesn't match confirmation",
          :accepted => "must be accepted",
          :empty => "can't be empty",
          :blank => "can't be blank",
          :too_long => "is too long (maximum is {{count}} characters)",
          :too_short => "is too short (minimum is {{count}} characters)",
          :wrong_length => "is the wrong length (should be {{count}} characters)",
          :taken => "has already been taken",
          :not_a_number => "is not a number",
          :greater_than => "must be greater than {{count}}",
          :greater_than_or_equal_to => "must be greater than or equal to {{count}}",
          :equal_to => "must be equal to {{count}}",
          :less_than => "must be less than {{count}}",
          :less_than_or_equal_to => "must be less than or equal to {{count}}",
          :odd => "must be odd",
          :even => "must be even"
      }
  }

}

Matthew Hutchinson