提交 8cb7d460 编写于 作者: S Sven Fuchs 提交者: Pratik Naik

I18n: move old-style interpolation syntax deprecation to Active Record. [#1044 state:resolved]

Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 9d7f186f
......@@ -77,5 +77,5 @@
require 'active_record/schema_dumper'
require 'active_record/i18n_interpolation_deprecation'
I18n.load_translations File.dirname(__FILE__) + '/active_record/locale/en-US.yml'
# 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
......@@ -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 @@ def pluralize(locale, entry, count)
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册