2009-04-23 5 views
7

Estoy actualizando una aplicación una aplicación de carriles a 2.3.2 y estoy descubriendo que no puedo mostrar los mensajes de error de validación por defecto para ActiveRecord porque no tengo un archivo de traducción para él.¿Hay un archivo de traducción inglés predeterminado para Active Record?

Este es el error que se informa:

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 

¿Alguien sabe donde puedo encontrar un archivo de traducción Inglés por defecto que incluiría todas las cadenas que las validaciones podrían usar?

Respuesta

14

Esto sucedió porque mi configuración de idioma era 'en-US' y no 'en'. Hay archivos de traducción en activerecord/lib/locale. Copié estas traducciones en un nuevo archivo 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" 

Luego acabo de agregar mis cadenas personalizadas después de estos.

+1

cuando he cambiado de forma predeterminada con la norma EN -US También necesitaba las claves encontradas [aquí] (https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml). – Jared

0

FYI, si los está incluyendo en el formato hash de estilo anterior, use esto;

: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

Puede evitar copiar y pegar las traducciones estándar diciéndole a I18n vuelve a los: es cuando no puede encontrar una traducción en: es. El ejemplo de inicialización siguiente muestra cómo lo hicimos para volver a caer a partir 'en-GB' y 'it-IT' a la standrd 'es', lanzando en pluralizations una buena medida

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