From 162934a2515da08ec8dfe8d22cbafd39694ebfa1 Mon Sep 17 00:00:00 2001 From: DM Date: Wed, 10 May 2017 14:58:41 +0300 Subject: [PATCH] Handle false as a key correctly --- lib/i18n/backend/base.rb | 2 +- test/i18n_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index 668a4221..124d9ef5 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -23,7 +23,7 @@ def store_translations(locale, data, options = {}) def translate(locale, key, options = {}) raise InvalidLocale.new(locale) unless locale - entry = key && lookup(locale, key, options[:scope], options) + entry = lookup(locale, key, options[:scope], options) unless key.nil? if entry.nil? && options.key?(:default) entry = default(locale, key, options[:default], options) diff --git a/test/i18n_test.rb b/test/i18n_test.rb index f92eefd4..0f72c299 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -6,6 +6,7 @@ def setup super store_translations(:en, :currency => { :format => { :separator => '.', :delimiter => ',', } }) store_translations(:nl, :currency => { :format => { :separator => ',', :delimiter => '.', } }) + store_translations(:en, "true" => "Yes", "false" => "No") end test "exposes its VERSION constant" do @@ -228,6 +229,14 @@ def setup end end + test "translate given true as a key works" do + assert_equal "Yes", I18n.t(true) + end + + test "translate given false as a key works" do + assert_equal "No", I18n.t(false) + end + test "available_locales can be replaced at runtime" do begin I18n.config.enforce_available_locales = true