From 62f005345127828d4ead038ac35ef1b2ba7ebbef Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 21 Jun 2023 20:19:41 +1000 Subject: [PATCH] Pass options to along to exists? super calls Fixes #670 --- lib/i18n/backend/fallbacks.rb | 2 +- test/backend/fallbacks_test.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/i18n/backend/fallbacks.rb b/lib/i18n/backend/fallbacks.rb index 6d4d6e13..a88a4fca 100644 --- a/lib/i18n/backend/fallbacks.rb +++ b/lib/i18n/backend/fallbacks.rb @@ -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 diff --git a/test/backend/fallbacks_test.rb b/test/backend/fallbacks_test.rb index 8c20a04b..5de18d35 100644 --- a/test/backend/fallbacks_test.rb +++ b/test/backend/fallbacks_test.rb @@ -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 @@ -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