Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #181 from grosser/chain-namespace-merge

do not overwrite response of first backend with later backends when looking up namespaces
  • Loading branch information...
commit a1f6552fca4a918fdae5ca7789012a990ab3c8fe 2 parents df79fa5 + ee7a102
@knapo knapo authored
Showing with 7 additions and 4 deletions.
  1. +1 −2  lib/i18n/backend/chain.rb
  2. +6 −2 test/backend/chain_test.rb
View
3  lib/i18n/backend/chain.rb
@@ -45,8 +45,7 @@ def translate(locale, key, default_options = {})
options = default_options if backend == backends.last
translation = backend.translate(locale, key, options)
if namespace_lookup?(translation, options)
- namespace ||= {}
- namespace.merge!(translation)
+ namespace = translation.merge(namespace || {})
elsif !translation.nil?
return translation
end
View
8 test/backend/chain_test.rb
@@ -3,10 +3,10 @@
class I18nBackendChainTest < Test::Unit::TestCase
def setup
@first = backend(:en => {
- :foo => 'Foo', :formats => { :short => 'short' }, :plural_1 => { :one => '%{count}' }
+ :foo => 'Foo', :formats => { :short => 'short' }, :plural_1 => { :one => '%{count}' }, :dates => {:a => "A"}
})
@second = backend(:en => {
- :bar => 'Bar', :formats => { :long => 'long' }, :plural_2 => { :one => 'one' }
+ :bar => 'Bar', :formats => { :long => 'long' }, :plural_2 => { :one => 'one' }, :dates => {:a => "B", :b => "B"}
})
@chain = I18n.backend = I18n::Backend::Chain.new(@first, @second)
end
@@ -42,6 +42,10 @@ def setup
assert_equal({ :short => 'short', :long => 'long' }, I18n.t(:formats))
end
+ test "namespace lookup collects results from all backends and does not overwrite" do
+ assert_equal({ :a => "A", :b => "B" }, I18n.t(:dates))
+ end
+
test "namespace lookup with only the first backend returning a result" do
assert_equal({ :one => '%{count}' }, I18n.t(:plural_1))
end
Please sign in to comment.
Something went wrong with that request. Please try again.