diff options
author | Sven Fuchs <svenfuchs@artweb-design.de> | 2008-09-14 13:36:06 +0200 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-09-20 19:13:50 +0100 |
commit | 8cb7d460439a9b20a80a77b6370c1107233d1cbd (patch) | |
tree | ddd5d29a0ab3f39e685ed35dc681a58114acf309 /activerecord/lib | |
parent | 9d7f186f746f38367851355fcd301ac24d6f6a51 (diff) | |
download | rails-8cb7d460439a9b20a80a77b6370c1107233d1cbd.tar.gz rails-8cb7d460439a9b20a80a77b6370c1107233d1cbd.tar.bz2 rails-8cb7d460439a9b20a80a77b6370c1107233d1cbd.zip |
I18n: move old-style interpolation syntax deprecation to Active Record. [#1044 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/i18n_interpolation_deprecation.rb | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index a6bbd6fc82..3f24170ce1 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 0000000000..cd634e1b8d --- /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 |