Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request ruby-i18n#130 from tomhughes/master
Browse files Browse the repository at this point in the history
Allow mutually recursive fallbacks
  • Loading branch information
tigrish committed Jul 5, 2012
2 parents c264f47 + 025d412 commit af62c27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/i18n/locale/fallbacks.rb
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/locale/fallbacks_test.rb
Expand Up @@ -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.