From 5ba6598e4ca08b3bc721fe92c1ed13bae1a87e3b Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 14 Sep 2008 13:36:06 +0200 Subject: [PATCH] I18n: move old-style interpolation syntax deprecation to activerecord --- activerecord/lib/active_record.rb | 2 +- .../i18n_interpolation_deprecation.rb | 26 ++++++++++++++++++++ .../vendor/i18n-0.0.1/i18n/backend/simple.rb | 7 ----- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 activerecord/lib/active_record/i18n_interpolation_deprecation.rb diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index a6bbd6f..3f24170 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -77,5 +77,5 @@ require 'active_record/connection_adapters/abstract_adapter' require 'active_record/schema_dumper' +require 'active_record/i18n_interpolation_deprecation' I18n.load_translations File.dirname(__FILE__) + '/active_record/locale/en-US.yml' - diff --git a/activerecord/lib/active_record/i18n_interpolation_deprecation.rb b/activerecord/lib/active_record/i18n_interpolation_deprecation.rb new file mode 100644 index 0000000..1f40f1d --- /dev/null +++ b/activerecord/lib/active_record/i18n_interpolation_deprecation.rb @@ -0,0 +1,26 @@ +# Deprecates the use of the former message interpolation syntax in activerecord +# as in "must have %d characters". The new syntax uses explicit variable names +# as in "{{value}} must have {{count}} characters". + +require 'i18n/backend/simple' +module I18n + module Backend + class Simple + DEPRECATED_INTERPOLATORS = { '%d' => '{{count}}', '%s' => '{{value}}' } + + protected + def interpolate_with_deprecated_syntax(locale, string, values = {}) + return string unless string.is_a?(String) + + string = string.gsub(/%d|%s/) do |s| + instead = DEPRECATED_INTERPOLATORS[s] + ActiveSupport::Deprecation.warn "using #{s} in messages is deprecated; use #{instead} instead." + instead + end + + interpolate_without_deprecated_syntax(locale, string, values) + end + alias_method_chain :interpolate, :deprecated_syntax + end + end +end \ No newline at end of file diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb index e2d19cd..ff15d83 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb @@ -4,7 +4,6 @@ module I18n module Backend class Simple INTERPOLATION_RESERVED_KEYS = %w(scope default) - DEPRECATED_INTERPOLATORS = { '%d' => '{{count}}', '%s' => '{{value}}' } MATCH = /(\\\\)?\{\{([^\}]+)\}\}/ # Accepts a list of paths to translation files. Loads translations from @@ -120,12 +119,6 @@ module I18n def interpolate(locale, string, values = {}) return string unless string.is_a?(String) - string = string.gsub(/%d|%s/) do |s| - instead = DEPRECATED_INTERPOLATORS[s] - ActiveSupport::Deprecation.warn "using #{s} in messages is deprecated; use #{instead} instead." - instead - end - if string.respond_to?(:force_encoding) original_encoding = string.encoding string.force_encoding(Encoding::BINARY) -- 1.5.3.7