Skip to content

Commit

Permalink
Merge pull request #367 from dimko/patch-1
Browse files Browse the repository at this point in the history
Handle false as a key correctly
  • Loading branch information
radar committed May 30, 2017
2 parents b04a982 + 162934a commit 1641e5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/backend/base.rb
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/i18n_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1641e5f

Please sign in to comment.