2009-04-23 8 views
7

मैं एक आवेदन को 2.3.2 पर एक रेल एप्लिकेशन को अपग्रेड कर रहा हूं और मुझे लगता है कि मैं ActiveRecord के लिए डिफ़ॉल्ट सत्यापन त्रुटि संदेश प्रदर्शित नहीं कर सकता क्योंकि मेरे पास इसके लिए अनुवाद फ़ाइल नहीं है।क्या सक्रिय रिकॉर्ड के लिए कोई डिफ़ॉल्ट अंग्रेज़ी अनुवाद फ़ाइल है?

यह त्रुटि है बताया जाता है कि:

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

ऐसा इसलिए हुआ क्योंकि मेरी भाषा सेटिंग 'एन-यूएस' थी और 'एन' नहीं थी। 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

जब मैं करने के लिए मेरे डिफ़ॉल्ट बदल एन से वापस गिरने के लिए यह किया - मुझे भी [कुंजी] मिली [https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml) की चाबियों की भी आवश्यकता है। – Jared

0

एफवाईआई, यदि आप पुराने स्टाइल हैश प्रारूप में इन्हें शामिल कर रहे हैं, तो इसका उपयोग करें;

: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 बताकर मानक अनुवाद कर सकते हैं: एन जब यह एक अनुवाद नहीं मिल सकता है: hi। नीचे दिए गए उदाहरण प्रारंभकर्ता दिखाता है कि हम 'en-GB' और 'यह आईटी' standrd 'en', अच्छा उपाय pluralizations में फेंकने के लिए

# 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) 
संबंधित मुद्दे