我正在将应用程序的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
有谁知道我在哪里可以找到一个默认的英文翻译文件,其中包含验证可能使用的所有字符串?
答案 0 :(得分:14)
这是因为我的语言环境是'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"
然后我在这些之后添加了自定义字符串。
答案 1 :(得分:1)
您可以通过告知I18n回退到以下内容来避免复制和粘贴标准翻译:当en无法在以下位置找到翻译时:en_US。下面的示例初始化程序显示了我们如何从'en-GB'和'it-IT'退回到standrd'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)
答案 2 :(得分: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"
}
}
}