Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #130 from tomhughes/master

Allow mutually recursive fallbacks
  • Loading branch information...
commit af62c277a14e0451b38ba454fb9fe9de826f300f 2 parents c264f47 + 025d412
@tigrish tigrish authored
Showing with 15 additions and 3 deletions.
  1. +3 −3 lib/i18n/locale/fallbacks.rb
  2. +12 −0 test/locale/fallbacks_test.rb
View
6 lib/i18n/locale/fallbacks.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
View
12 test/locale/fallbacks_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.