2009-04-23 6 views
7

Я обновляю приложение приложение rails до 2.3.2, и обнаруживаю, что я не могу отображать сообщения об ошибках проверки по умолчанию для ActiveRecord, потому что у меня нет файла перевода.Есть ли файл перевода по умолчанию для Active Record?

Это ошибка, которая сообщается:

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 

Кто-нибудь знает, где я могу найти английский файл перевода по умолчанию, который будет включать в себя все строки, что валидация может использовать?

ответ

14

Это произошло потому, что мой язык был «en-US», а не «en». Есть файлы перевода в файле activerecord/lib/locale. Я скопировал эти переводы в новый файл 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" 

Тогда я просто добавил свои пользовательские строки после них.

+1

, когда я изменил свое значение по умолчанию для ванной -US Мне также нужны ключи, найденные здесь (https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml). – Jared

0

FYI, если вы включили их в хэш-формат старого стиля, используйте это;

: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" 
     } 
    } 

}

1

Вы можете избежать копирования и вставки стандартных переводов, рассказав I18N в Откат к: ан, когда он не может найти перевод: en_US. Пример инициализатор ниже показывает, как мы сделали это для отступая от «ан-ГБ» и «он-IT» в Standrd «ан», бросание в множественном числе для ровного

# config/initializer/i18n.rb 

I18n.backend = I18n::Backend::Chain.new(I18n.backend) 
I18n::Backend::Chain.send(:include, I18n::Backend::Fallbacks) 
I18n.fallbacks[:'en-GB'] << :en 
I18n.fallbacks[:'it-IT'] << :en 

require "i18n/backend/pluralization" 
I18n::Backend::Chain.send(:include, I18n::Backend::Pluralization) 

 Смежные вопросы

  • Нет связанных вопросов^_^