Skip to content

Commit

Permalink
Merge pull request #647 from misdoro/exists_scope
Browse files Browse the repository at this point in the history
Allow passing scope argument to exists?
  • Loading branch information
radar authored Feb 3, 2023
2 parents d94228c + 2545b8d commit c635958
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def translate(locale, key, options = EMPTY_HASH)
end

def exists?(locale, key, options = EMPTY_HASH)
lookup(locale, key) != nil
lookup(locale, key, options[:scope]) != nil
end

# Acts the same as +strftime+, but uses a localized version of the
Expand Down
4 changes: 4 additions & 0 deletions test/i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ def setup
assert_equal true, I18n.exists?(:currency, :nl)
end

test "exists? given an existing key and a scope will return true" do
assert_equal true, I18n.exists?(:delimiter, scope: [:currency, :format])
end

test "exists? given a non-existing key and an existing locale will return false" do
assert_equal false, I18n.exists?(:bogus, :nl)
end
Expand Down

0 comments on commit c635958

Please sign in to comment.