Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
knapo committed Dec 19, 2012
2 parents df79fa5 + ee7a102 commit a1f6552
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/i18n/backend/chain.rb
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions test/backend/chain_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a1f6552

Please sign in to comment.