From 8a1b54fd7bc4764d5daf1f1deac61fc86f7b46c0 Mon Sep 17 00:00:00 2001 From: Oleksii Leonov Date: Sun, 6 Jan 2019 21:46:05 +0200 Subject: [PATCH] Fix regression with leading zero keys Fix #456. --- lib/i18n.rb | 2 +- test/backend/simple_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/i18n.rb b/lib/i18n.rb index bc81aff2..dbf1384b 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -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 diff --git a/test/backend/simple_test.rb b/test/backend/simple_test.rb index 7ec3f6c3..e6bb140c 100644 --- a/test/backend/simple_test.rb +++ b/test/backend/simple_test.rb @@ -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')