7

我正在将一个应用程序从一个 rails 应用程序升级到 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

有谁知道我在哪里可以找到包含验证可能使用的所有字符串的默认英语翻译文件?

4

3 回答 3

15

发生这种情况是因为我的语言设置是“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"

然后我只是在这些之后添加了我的自定义字符串。

于 2009-04-30T00:06:40.060 回答
1

当 I18n 在 :en_US 中找不到翻译时,您可以通过告诉 I18n 回退到 :en 来避免复制和粘贴标准翻译。下面的示例初始化程序显示了我们如何从“en-GB”和“it-IT”回退到标准“en”,并使用复数形式来衡量

# 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)
于 2013-08-19T13:58:13.153 回答
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"
      }
  }

}

于 2009-06-09T11:55:25.930 回答