~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activerecord/lib/active_record/i18n_interpolation_deprecation.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Deprecates the use of the former message interpolation syntax in activerecord
2
 
# as in "must have %d characters". The new syntax uses explicit variable names
3
 
# as in "{{value}} must have {{count}} characters".
4
 
 
5
 
require 'i18n/backend/simple'
6
 
module I18n
7
 
  module Backend
8
 
    class Simple
9
 
      DEPRECATED_INTERPOLATORS = { '%d' => '{{count}}', '%s' => '{{value}}' }
10
 
 
11
 
      protected
12
 
        def interpolate_with_deprecated_syntax(locale, string, values = {})
13
 
          return string unless string.is_a?(String) && !values.empty?
14
 
 
15
 
          string = string.gsub(/%d|%s/) do |s|
16
 
            instead = DEPRECATED_INTERPOLATORS[s]
17
 
            ActiveSupport::Deprecation.warn "using #{s} in messages is deprecated; use #{instead} instead."
18
 
            instead
19
 
          end
20
 
 
21
 
          interpolate_without_deprecated_syntax(locale, string, values)
22
 
        end
23
 
        alias_method_chain :interpolate, :deprecated_syntax
24
 
    end
25
 
  end
26
 
end
 
 
b'\\ No newline at end of file'