Permalink
Browse files

Merge pull request #130 from tomhughes/master

Allow mutually recursive fallbacks
  • Loading branch information...
2 parents c264f47 + 025d412 commit af62c277a14e0451b38ba454fb9fe9de826f300f @tigrish tigrish committed Jul 5, 2012
Showing with 15 additions and 3 deletions.
  1. +3 −3 lib/i18n/locale/fallbacks.rb
  2. +12 −0 test/locale/fallbacks_test.rb
@@ -82,10 +82,10 @@ def map(mappings)
protected
- def compute(tags, include_defaults = true)
+ def compute(tags, include_defaults = true, exclude = [])
result = Array(tags).collect do |tag|
- tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym }
- tags.each { |_tag| tags += compute(@map[_tag]) if @map[_tag] }
+ tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym } - exclude
+ tags.each { |_tag| tags += compute(@map[_tag], false, exclude + tags) if @map[_tag] }
tags
end.flatten
result.push(*defaults) if include_defaults
@@ -121,4 +121,16 @@ def setup
test "with a mapping :de => :en, :he => :en defined it [:he, :en] for :de" do
assert_equal [:he, :"en-US", :en], @fallbacks[:he]
end
+
+ # Test allowing mappings that fallback to each other
+
+ test "with :no => :nb, :nb => :no defined :no returns [:no, :nb, :en-US, :en]" do
+ @fallbacks.map(:no => :nb, :nb => :no)
+ assert_equal [:no, :nb, :"en-US", :en], @fallbacks[:no]
+ end
+
+ test "with :no => :nb, :nb => :no defined :nb returns [:nb, :no, :en-US, :en]" do
+ @fallbacks.map(:no => :nb, :nb => :no)
+ assert_equal [:nb, :no, :"en-US", :en], @fallbacks[:nb]
+ end
end

0 comments on commit af62c27

Please sign in to comment.