mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
I18n: move old-style interpolation syntax deprecation to Active Record. [#1044 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
parent
9d7f186f74
commit
8cb7d46043
3 changed files with 27 additions and 8 deletions
|
@ -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'
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue