Skip to content

Commit

Permalink
translate with default value should check all the fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Jul 9, 2011
1 parent 2778870 commit 3746542
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/backend/fallbacks.rb
Expand Up @@ -60,7 +60,7 @@ def extract_string_or_lambda_default!(options)
end

def find_first_string_or_lambda_default(defaults)
defaults.each_with_index { |default, ix| return ix if String === default || Proc === default }
defaults.each_with_index { |default, ix| return ix if default && !default.is_a?(Symbol) }
nil
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/backend/fallbacks_test.rb
Expand Up @@ -48,6 +48,11 @@ def setup
assert_equal "Default Bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => Proc.new { "Default Bar" })
end

test "returns the :de translation for a missing :'de-DE' when :default is a Hash" do
assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE', :default => {})
assert_equal({}, I18n.t(:missing_bar, :locale => :'de-DE', :default => {}))
end

test "returns the :'de-DE' default :baz translation for a missing :'de-DE' when defaults contains Symbol" do
assert_equal 'Baz in :de-DE', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:baz, "Default Bar"])
end
Expand Down

0 comments on commit 3746542

Please sign in to comment.