Skip to content

Commit

Permalink
Fix regression with leading zero keys
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksii-leonov committed Jan 6, 2019
1 parent d8a2d5c commit 8a1b54f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def normalize_key(key, separator)
keys.delete('')
keys.map! do |k|
case k
when /\A[-+]?\d+\z/ # integer
when /\A[-+]?[1-9]\d*\z/ # integer
k.to_i
when 'true'
true
Expand Down
6 changes: 6 additions & 0 deletions test/backend/simple_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def setup
assert_equal "Yes", I18n.t('available.1')
end

test 'simple backend translate: given integer with a lead zero as a key' do
store_translations :en, available: { '01' => 'foo' }
assert_equal 'foo', I18n.t(:available)[:'01']
assert_equal 'foo', I18n.t('available.01')
end

test "simple backend translate: symbolize keys in hash" do
store_translations :en, nested_hashes_in_array: { hello: "world" }
assert_equal "world", I18n.t('nested_hashes_in_array.hello')
Expand Down

0 comments on commit 8a1b54f

Please sign in to comment.