FIX: Pluralization error when overriding translations.

This commit is contained in:
Guo Xiang Tan
2015-12-29 10:31:23 +08:00
parent 0613399d7a
commit e89f29cca7
2 changed files with 35 additions and 4 deletions

View File

@ -62,12 +62,24 @@ module I18n
results
end
# Support interpolation and pluralization of overrides by first looking up
# the original translations before applying our overrides.
def lookup(locale, key, scope = [], options = {})
# Support interpolation and pluralization of overrides
if options[:overrides]
existing_translations = super(locale, key, scope, options)
if options[:overrides] && existing_translations
if options[:count]
existing_translations =
if existing_translations.is_a?(Hash)
Hash[existing_translations.map { |k, v| [k.to_s.prepend("#{key}."), v] }]
elsif existing_translations.is_a?(String)
Hash[[[key, existing_translations]]]
end
result = {}
options[:overrides].each do |k, v|
existing_translations.merge(options[:overrides]).each do |k, v|
result[k.split('.').last.to_sym] = v if k != key && k.start_with?(key.to_s)
end
return result if result.size > 0
@ -76,7 +88,7 @@ module I18n
return options[:overrides][key] if options[:overrides][key]
end
super(locale, key, scope, options)
existing_translations
end
end