Skip to content

Commit

Permalink
Fix regression for handling zero integer keys
Browse files Browse the repository at this point in the history
They should be treated consistently with other integer-like keys.

See [ruby-i18n#456] and [ruby-i18n#457] for reference.

[ruby-i18n#456]: ruby-i18n#456
[ruby-i18n#457]: ruby-i18n#457
  • Loading branch information
Envek committed Feb 26, 2019
1 parent 70daba7 commit e85bbb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def normalize_key(key, separator)
keys.delete('')
keys.map! do |k|
case k
when /\A[-+]?[1-9]\d*\z/ # integer
when /\A(?:0|[-+]?[1-9]\d*)\z/ # integer
k.to_i
when 'true'
true
Expand Down
6 changes: 5 additions & 1 deletion test/backend/simple_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ def setup
end

test "simple backend translate: given integer as a key" do
store_translations :en, available: { 1 => "Yes", 2 => "No" }
store_translations :en, available: { 0 => "Dunno", 1 => "Yes", 2 => "No" }
assert_equal "Dunno", I18n.t(:available)[0]
assert_equal "Dunno", I18n.t('available.0')
assert_equal "Yes", I18n.t(:available)[1]
assert_equal "Yes", I18n.t('available.1')
assert_equal "No", I18n.t(:available)[2]
assert_equal "No", I18n.t('available.2')
end

test 'simple backend translate: given integer with a lead zero as a key' do
Expand Down

0 comments on commit e85bbb3

Please sign in to comment.