Skip to content

Commit

Permalink
Merge pull request #671 from ruby-i18n/exists-pass-options
Browse files Browse the repository at this point in the history
Pass options to along to exists? super calls
  • Loading branch information
radar authored Jun 21, 2023
2 parents 395aa5e + 62f0053 commit 075e1ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/i18n/backend/fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def exists?(locale, key, options = EMPTY_HASH)
return super unless options.fetch(:fallback, true)
I18n.fallbacks[locale].each do |fallback|
begin
return true if super(fallback, key)
return true if super(fallback, key, options)
rescue I18n::InvalidLocale
# we do nothing when the locale is invalid, as this is a fallback anyways.
end
Expand Down
6 changes: 5 additions & 1 deletion test/backend/fallbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class Chain < I18n::Backend::Chain
def setup
super
backend = Backend.new
backend.store_translations(:de, :foo => 'FOO')
backend.store_translations(:de, :foo => 'FOO', :nested => { key: "value" })
backend.store_translations(:'pt-BR', :foo => 'Baz in :pt-BR')
I18n.backend = Chain.new(I18n::Backend::Simple.new, backend)
end
Expand All @@ -325,6 +325,10 @@ def setup
assert_equal true, I18n.exists?(:foo, :locale => :'de-DE')
end

test "exists? passes along the scope option" do
assert_equal true, I18n.exists?(:key, :locale => :'de-DE', scope: :nested)
end

test "exists? should return false when fallback disabled given a key missing from the given locale" do
assert_equal false, I18n.exists?(:foo, :locale => :'de-DE', fallback: false)
end
Expand Down

0 comments on commit 075e1ab

Please sign in to comment.