2009-04-23 7 views
7

Ich aktualisiere eine Anwendung eine Rails-Anwendung auf 2.3.2 und ich stelle fest, dass ich die Standardvalidierungsfehlermeldungen für ActiveRecord nicht anzeigen kann, da ich keine Übersetzungsdatei dafür habe.Gibt es eine englische Standardübersetzungsdatei für Active Record?

Dies ist der Fehler, wird berichtet:

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 

Weiß jemand, wo ich eine Standard-Englisch Übersetzungsdatei finden kann, die alle Fäden umfassen würden, die die Validierungen verwenden könnten?

Antwort

14

Dies passierte, weil meine Spracheinstellung 'en-US' und nicht 'en' war. Es gibt Übersetzungsdateien unter activerecord/lib/locale. Ich habe diese Übersetzungen in eine neue Datei en_US.yml kopiert.

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

Dann habe ich meine benutzerdefinierten Strings nach diesen hinzugefügt.

+1

wenn ich zu meinem Standard geändert en -US Ich brauchte auch die gefundenen Schlüssel [hier] (https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml). – Jared

0

FYI, wenn Sie diese im alten Stil-Hash-Format enthalten, verwenden Sie dies;

: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

Sie können Kopieren vermeiden und die Standardübersetzungen einfügen I18n indem ich auf zu Rückfall: en, wenn es keine Übersetzung in: de_DE. Das Beispiel initializer unten zeigt, wie wir es getan haben für Absturz aus zurück ‚en-GB‘ und ‚it-IT‘ zum standrd ‚en‘, in pluralizations für eine gute Maßnahme zu werfen

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