Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make merge_translations merge a given value or hash over a previously…

… set nil value. should probably raise a TypeError instead because the given translation data seems flawed
  • Loading branch information...
commit f2b929a1d0805759902539265be316e5becdf4a7 1 parent ed86aaa
@svenfuchs authored
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/i18n/backend/base.rb
View
8 lib/i18n/backend/base.rb
@@ -227,7 +227,7 @@ def interpolate_lambda?(object, string, key)
def load_file(filename)
type = File.extname(filename).tr('.', '').downcase
raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}")
- data = send :"load_#{type}", filename # TODO raise a meaningful exception if this does not yield a Hash
+ data = send(:"load_#{type}", filename) # TODO raise a meaningful exception if this does not yield a Hash
data.each { |locale, d| merge_translations(locale, d) }
end
@@ -251,7 +251,11 @@ def merge_translations(locale, data)
data = deep_symbolize_keys(data)
# deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
- merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
+ merger = proc do |key, v1, v2|
+ # TODO should probably be:
+ # raise TypeError.new("can't merge #{v1.inspect} and #{v2.inspect}") unless Hash === v1 && Hash === v2
+ Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : (v2 || v1)
+ end
translations[locale].merge!(data, &merger)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.