From cdc0babfbdbc6babed5030ec7a79a3d75deab55b Mon Sep 17 00:00:00 2001 From: Bilka Date: Tue, 12 Mar 2024 13:43:22 +0100 Subject: [PATCH 1/2] Fix that escaped interpolations for reserved keywords raised an error --- lib/i18n.rb | 2 +- lib/i18n/tests/interpolation.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/i18n.rb b/lib/i18n.rb index d3369704..18c3c761 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -48,7 +48,7 @@ def self.reserve_key(key) end def self.reserved_keys_pattern # :nodoc: - @reserved_keys_pattern ||= /%\{(#{RESERVED_KEYS.join("|")})\}/ + @reserved_keys_pattern ||= /(? :bar, :default => '%%{separator}') + end + + assert_nothing_raised do + assert_equal '%%{scope}', interpolate(:default => '%%{scope}') + end + + I18n.backend.store_translations(:en, :interpolate => 'Hi %%{scope}!') + assert_nothing_raised do + assert_equal 'Hi %%{scope}!', interpolate(:interpolate) + end + end + test "interpolation: deep interpolation for default string" do assert_equal 'Hi %{name}!', interpolate(:default => 'Hi %{name}!', :deep_interpolation => true) end From 8f4bca1ff5f1d15d948c4c783edb9c4e8987baf7 Mon Sep 17 00:00:00 2001 From: Bilka Date: Sat, 30 Mar 2024 08:22:22 +0100 Subject: [PATCH 2/2] Add note about not altering strings when no params are given --- lib/i18n/tests/interpolation.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/i18n/tests/interpolation.rb b/lib/i18n/tests/interpolation.rb index 1ff12f24..03c67db7 100644 --- a/lib/i18n/tests/interpolation.rb +++ b/lib/i18n/tests/interpolation.rb @@ -123,6 +123,9 @@ module Interpolation assert_equal '%{separator}', interpolate(:foo => :bar, :default => '%%{separator}') end + # Note: The two interpolations below do not remove the escape character (%) because + # I18n should not alter the strings when no interpolation parameters are given, + # see the comment at the top of this file. assert_nothing_raised do assert_equal '%%{scope}', interpolate(:default => '%%{scope}') end