From 635a1b58acf5dad99b597acdd717b9b3a115bfae Mon Sep 17 00:00:00 2001 From: Lukas Spee Date: Thu, 22 Oct 2009 19:45:53 +0200 Subject: [PATCH] Make i18n interpolation of escaped interpolation keys conform to documented behaviour --- .../vendor/i18n-0.1.3/lib/i18n/backend/simple.rb | 6 +++--- .../vendor/i18n-0.1.3/test/simple_backend_test.rb | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb index c32cc76..6ad6f33 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb @@ -4,7 +4,7 @@ module I18n module Backend class Simple INTERPOLATION_RESERVED_KEYS = %w(scope default) - MATCH = /(\\\\)?\{\{([^\}]+)\}\}/ + MATCH = /(\\\\)?(\{\{([^\}]+)\}\})/ # Accepts a list of paths to translation files. Loads translations from # plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml @@ -152,10 +152,10 @@ module I18n return string unless string.is_a?(String) string.gsub(MATCH) do - escaped, pattern, key = $1, $2, $2.to_sym + escaped, placeholder, pattern, key = $1, $2, $3, $3.to_sym if escaped - pattern + placeholder elsif INTERPOLATION_RESERVED_KEYS.include?(pattern) raise ReservedInterpolationKey.new(pattern, string) elsif !values.include?(key) diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb b/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb index a1696c7..fe63e08 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb @@ -297,9 +297,13 @@ class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key assert_raise(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, nil, '{{default}}', {:default => nil}) } end - + + def test_given_a_string_containing_an_escaped_interpolation_key + assert_equal 'Hi {{name}}', @backend.send(:interpolate, nil, 'Hi \\\\{{name}}', {}) + end + private - + def euc_jp(string) string.encode!(Encoding::EUC_JP) end @@ -539,27 +543,27 @@ end class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase include I18nSimpleBackendTestSetup - + def setup @backend = I18n::Backend::Simple.new I18n.load_path = [File.dirname(__FILE__) + '/locale/en.yml'] assert_nil backend_get_translations @backend.send :init_translations end - + def teardown I18n.load_path = [] end - + def test_setup assert_not_nil backend_get_translations end - + def test_reload_translations_unloads_translations @backend.reload! assert_nil backend_get_translations end - + def test_reload_translations_uninitializes_translations @backend.reload! assert_equal @backend.initialized?, false -- 1.6.2.2.404.ge96f3