Skip to content

Commit

Permalink
Fix string locale will trigger on_fallback hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
piecehealth committed Feb 25, 2021
1 parent aec9d66 commit ff6e0b4
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def translate(locale, key, options = EMPTY_HASH)
catch(:exception) do
result = super(fallback, key, fallback_options)
unless result.nil?
on_fallback(locale, fallback, key, options) if locale != fallback
on_fallback(locale, fallback, key, options) if locale.to_s != fallback.to_s
return result
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/backend/fallbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,9 @@ def setup
assert_equal [:'de-DE', :de, :bar, {}], I18n.backend.fallback_collector[0]
assert_equal [:'de-DE', :en, :foo, {}], I18n.backend.fallback_collector[1]
end

test "on_fallback should not be called when use a String locale" do
assert_equal 'Bar in :de', I18n.t("bar", locale: "de")
assert I18n.backend.fallback_collector.nil?
end
end

0 comments on commit ff6e0b4

Please sign in to comment.