diff --git a/lib/i18n/backend/chain.rb b/lib/i18n/backend/chain.rb index f88da2d0..123f7e3c 100644 --- a/lib/i18n/backend/chain.rb +++ b/lib/i18n/backend/chain.rb @@ -96,9 +96,13 @@ def init_translations end def translations - backends.first.instance_eval do - init_translations unless initialized? - translations + backends.reverse.each_with_object({}) do |backend, memo| + partial_translations = backend.instance_eval do + init_translations unless initialized? + translations + end + + memo.deep_merge!(partial_translations) end end diff --git a/test/backend/chain_test.rb b/test/backend/chain_test.rb index 50b16f3c..97e64b8f 100644 --- a/test/backend/chain_test.rb +++ b/test/backend/chain_test.rb @@ -107,16 +107,19 @@ def setup assert @second.initialized? end - test 'should be able to get all translations of the first backend' do + test 'should be able to get all translations of all backends merged together' do assert_equal I18n.backend.send(:translations), en: { foo: 'Foo', + bar: 'Bar', formats: { short: 'short', - subformats: { short: 'short' } + long: 'long', + subformats: { short: 'short', long: 'long' } }, plural_1: { one: "%{count}" }, - dates: { a: 'A' } + plural_2: { one: 'one' }, + dates: { a: 'A', b: 'B' } } end