Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle false as a key correctly #367

Merged
merged 1 commit into from May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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