diff --git a/lib/i18n.rb b/lib/i18n.rb index 2980f025..d63a1069 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -264,7 +264,8 @@ def interpolation_keys(key, **options) def exists?(key, _locale = nil, locale: _locale, **options) locale ||= config.locale raise Disabled.new('exists?') if locale == false - raise I18n::ArgumentError if key.is_a?(String) && key.empty? + raise I18n::ArgumentError if (key.is_a?(String) && key.empty?) || key.nil? + config.backend.exists?(locale, key, options) end diff --git a/test/i18n_test.rb b/test/i18n_test.rb index 85679d40..642920de 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -315,6 +315,10 @@ def setup assert_raises(I18n::ArgumentError) { I18n.interpolation_keys(["bad-argument"]) } end + test "exists? given nil raises I18n::ArgumentError" do + assert_raises(I18n::ArgumentError) { I18n.exists?(nil) } + end + test "exists? given an existing key will return true" do assert_equal true, I18n.exists?(:currency) end