2009-04-23 10 views
7

Tôi đang nâng cấp ứng dụng một ứng dụng đường ray lên 2.3.2 và tôi thấy rằng tôi không thể hiển thị các thông báo lỗi xác thực mặc định cho ActiveRecord vì tôi không có tệp dịch cho nó.Có tệp dịch tiếng Anh mặc định cho Bản ghi Hoạt động không?

Đây là lỗi được báo cáo:

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 

Có ai biết nơi tôi có thể tìm thấy một tập tin bản dịch tiếng Anh mặc định mà sẽ bao gồm tất cả các chuỗi kiểm chứng thực có thể sử dụng không?

Trả lời

14

Điều này xảy ra do cài đặt ngôn ngữ của tôi là 'en-US' chứ không phải 'en'. Có các tệp dịch theo activerecord/lib/locale. Tôi đã sao chép các bản dịch này sang một tệp mới 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" 

Sau đó, tôi vừa thêm các chuỗi tùy chỉnh của mình sau đó.

+1

khi tôi thay đổi mặc định của tôi để en -US Tôi cũng cần các phím được tìm thấy [ở đây] (https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml). – Jared

0

FYI, nếu bạn bao gồm các định dạng này trong định dạng băm cũ, hãy sử dụng tính năng này;

: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

Bạn có thể tránh việc sao chép và dán bản dịch tiêu chuẩn bằng cách nói i18n để dự phòng để: en khi nó không thể tìm thấy một bản dịch trong: en_US. Ví dụ initializer dưới đây cho thấy cách chúng tôi đã làm nó cho rơi trở lại từ 'en-GB' và 'it-IT' đến standrd 'en', ném trong pluralizations cho biện pháp tốt

# 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)