Skip to content

Commit

Permalink
Merge pull request #562 from piecehealth/fix_on_fallback
Browse files Browse the repository at this point in the history
Fix string locale will trigger on_fallback hook.
  • Loading branch information
radar committed Mar 30, 2021
2 parents aec9d66 + ff6e0b4 commit a469561
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 @@ -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
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 a469561

Please sign in to comment.