Merge pull request #12799 from Homebrew/revert-12797-dependabot/bundler/Library/Homebrew/i18n-1.9.0

Revert "build(deps): bump i18n from 1.8.11 to 1.9.0 in /Library/Homebrew"
This commit is contained in:
Nanda H Krishna 2022-01-27 17:20:28 -05:00 committed by GitHub
commit c40b2baf9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 232 additions and 171 deletions

View File

@ -33,7 +33,7 @@ GEM
hpricot (0.8.6) hpricot (0.8.6)
http-cookie (1.0.4) http-cookie (1.0.4)
domain_name (~> 0.5) domain_name (~> 0.5)
i18n (1.9.0) i18n (1.8.11)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
json_schemer (0.2.18) json_schemer (0.2.18)
ecma-re-validator (~> 0.3) ecma-re-validator (~> 0.3)

View File

@ -8,20 +8,9 @@ module I18n
extend ::I18n::Base extend ::I18n::Base
class << self class << self
def cache_key_digest; end
def cache_key_digest=(key_digest); end
def cache_namespace; end
def cache_namespace=(namespace); end
def cache_store; end
def cache_store=(store); end
def fallbacks; end
def fallbacks=(fallbacks); end
def interpolate(string, values); end def interpolate(string, values); end
def interpolate_hash(string, values); end def interpolate_hash(string, values); end
def new_double_nested_cache; end def new_double_nested_cache; end
def perform_caching?; end
def reserve_key(key); end
def reserved_keys_pattern; end
end end
end end
@ -87,10 +76,43 @@ module I18n::Backend::Cascade
def lookup(locale, key, scope = T.unsafe(nil), options = T.unsafe(nil)); end def lookup(locale, key, scope = T.unsafe(nil), options = T.unsafe(nil)); end
end end
class I18n::Backend::Chain
include ::I18n::Backend::Transliterator
include ::I18n::Backend::Base
include ::I18n::Backend::Chain::Implementation
end
module I18n::Backend::Chain::Implementation
include ::I18n::Backend::Transliterator
include ::I18n::Backend::Base
def initialize(*backends); end
def available_locales; end
def backends; end
def backends=(_arg0); end
def eager_load!; end
def exists?(locale, key, options = T.unsafe(nil)); end
def initialized?; end
def localize(locale, object, format = T.unsafe(nil), options = T.unsafe(nil)); end
def reload!; end
def store_translations(locale, data, options = T.unsafe(nil)); end
def translate(locale, key, default_options = T.unsafe(nil)); end
protected
def init_translations; end
def namespace_lookup?(result, options); end
def translations; end
private
def _deep_merge(hash, other_hash); end
end
module I18n::Backend::Fallbacks module I18n::Backend::Fallbacks
def exists?(locale, key, options = T.unsafe(nil)); end def exists?(locale, key, options = T.unsafe(nil)); end
def extract_non_symbol_default!(options); end def extract_non_symbol_default!(options); end
def resolve(locale, object, subject, options = T.unsafe(nil)); end
def translate(locale, key, options = T.unsafe(nil)); end def translate(locale, key, options = T.unsafe(nil)); end
private private
@ -120,6 +142,19 @@ end
I18n::Backend::Flatten::FLATTEN_SEPARATOR = T.let(T.unsafe(nil), String) I18n::Backend::Flatten::FLATTEN_SEPARATOR = T.let(T.unsafe(nil), String)
I18n::Backend::Flatten::SEPARATOR_ESCAPE_CHAR = T.let(T.unsafe(nil), String) I18n::Backend::Flatten::SEPARATOR_ESCAPE_CHAR = T.let(T.unsafe(nil), String)
module I18n::Backend::Gettext
protected
def load_po(filename); end
def normalize(locale, data); end
def normalize_pluralization(locale, key, value); end
def parse(filename); end
end
class I18n::Backend::Gettext::PoData < ::Hash
def set_comment(msgid_or_sym, comment); end
end
module I18n::Backend::InterpolationCompiler module I18n::Backend::InterpolationCompiler
def interpolate(locale, string, values); end def interpolate(locale, string, values); end
def store_translations(locale, data, options = T.unsafe(nil)); end def store_translations(locale, data, options = T.unsafe(nil)); end
@ -389,6 +424,7 @@ module I18n::Gettext::Helpers
end end
I18n::Gettext::PLURAL_SEPARATOR = T.let(T.unsafe(nil), String) I18n::Gettext::PLURAL_SEPARATOR = T.let(T.unsafe(nil), String)
module I18n::HashRefinements; end
I18n::INTERPOLATION_PATTERN = T.let(T.unsafe(nil), Regexp) I18n::INTERPOLATION_PATTERN = T.let(T.unsafe(nil), Regexp)
class I18n::InvalidLocale < ::I18n::ArgumentError class I18n::InvalidLocale < ::I18n::ArgumentError
@ -420,7 +456,7 @@ class I18n::Locale::Fallbacks < ::Hash
def [](locale); end def [](locale); end
def defaults; end def defaults; end
def defaults=(defaults); end def defaults=(defaults); end
def map(*args, &block); end def map(mappings); end
protected protected
@ -516,13 +552,12 @@ module I18n::MissingTranslation::Base
def to_s; end def to_s; end
end end
I18n::MissingTranslation::Base::PERMITTED_KEYS = T.let(T.unsafe(nil), Array)
class I18n::MissingTranslationData < ::I18n::ArgumentError class I18n::MissingTranslationData < ::I18n::ArgumentError
include ::I18n::MissingTranslation::Base include ::I18n::MissingTranslation::Base
end end
I18n::RESERVED_KEYS = T.let(T.unsafe(nil), Array) I18n::RESERVED_KEYS = T.let(T.unsafe(nil), Array)
I18n::RESERVED_KEYS_PATTERN = T.let(T.unsafe(nil), Regexp)
class I18n::ReservedInterpolationKey < ::I18n::ArgumentError class I18n::ReservedInterpolationKey < ::I18n::ArgumentError
def initialize(key, string); end def initialize(key, string); end
@ -545,11 +580,6 @@ module I18n::Tests::Interpolation; end
module I18n::Tests::Link; end module I18n::Tests::Link; end
module I18n::Tests::Localization module I18n::Tests::Localization
include ::I18n::Tests::Localization::Date
include ::I18n::Tests::Localization::DateTime
include ::I18n::Tests::Localization::Procs
include ::I18n::Tests::Localization::Time
class << self class << self
def included(base); end def included(base); end
end end
@ -583,17 +613,4 @@ class I18n::UnknownFileType < ::I18n::ArgumentError
def type; end def type; end
end end
module I18n::Utils
class << self
def deep_merge(hash, other_hash, &block); end
def deep_merge!(hash, other_hash, &block); end
def deep_symbolize_keys(hash); end
def except(hash, *keys); end
private
def deep_symbolize_keys_in_object(value); end
end
end
I18n::VERSION = T.let(T.unsafe(nil), String) I18n::VERSION = T.let(T.unsafe(nil), String)

View File

@ -2417,6 +2417,48 @@ module Gem
def self.remove_unresolved_default_spec(spec); end def self.remove_unresolved_default_spec(spec); end
end end
module GetText
end
class GetText::PoParser
def _(x); end
def _reduce_10(val, _values, result); end
def _reduce_12(val, _values, result); end
def _reduce_13(val, _values, result); end
def _reduce_14(val, _values, result); end
def _reduce_15(val, _values, result); end
def _reduce_5(val, _values, result); end
def _reduce_8(val, _values, result); end
def _reduce_9(val, _values, result); end
def _reduce_none(val, _values, result); end
def on_comment(comment); end
def on_message(msgid, msgstr); end
def parse(str, data, ignore_fuzzy=T.unsafe(nil)); end
def unescape(orig); end
Racc_arg = ::T.let(nil, ::T.untyped)
Racc_debug_parser = ::T.let(nil, ::T.untyped)
Racc_token_to_s_table = ::T.let(nil, ::T.untyped)
end
class GetText::PoParser
end
module GetText
end
module GitHub::API module GitHub::API
extend ::T::Private::Methods::MethodHooks extend ::T::Private::Methods::MethodHooks
extend ::T::Private::Methods::SingletonMethodHooks extend ::T::Private::Methods::SingletonMethodHooks
@ -2737,6 +2779,26 @@ end
module HostEnvironmentSimulatorHelper module HostEnvironmentSimulatorHelper
end end
module I18n
def self.cache_key_digest(); end
def self.cache_key_digest=(key_digest); end
def self.cache_namespace(); end
def self.cache_namespace=(namespace); end
def self.cache_store(); end
def self.cache_store=(store); end
def self.fallbacks(); end
def self.fallbacks=(fallbacks); end
def self.perform_caching?(); end
end
class IO class IO
def beep(); end def beep(); end
@ -4314,6 +4376,8 @@ module RSpec::Core::MockingAdapters
end end
class RSpec::Core::OutputWrapper class RSpec::Core::OutputWrapper
def as_json(*args, &block); end
def readline_nonblock(*args, &block); end def readline_nonblock(*args, &block); end
end end

View File

@ -4,7 +4,7 @@ ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
ruby_version = RbConfig::CONFIG["ruby_version"] ruby_version = RbConfig::CONFIG["ruby_version"]
path = File.expand_path('..', __FILE__) path = File.expand_path('..', __FILE__)
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.9.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.8.11/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.15.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/minitest-5.15.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tzinfo-2.0.4/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/tzinfo-2.0.4/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/zeitwerk-2.5.3/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/zeitwerk-2.5.3/lib"

View File

@ -4,7 +4,6 @@ require 'concurrent/map'
require 'concurrent/hash' require 'concurrent/hash'
require 'i18n/version' require 'i18n/version'
require 'i18n/utils'
require 'i18n/exceptions' require 'i18n/exceptions'
require 'i18n/interpolate/ruby' require 'i18n/interpolate/ruby'
@ -23,7 +22,6 @@ module I18n
exception_handler exception_handler
fallback fallback
fallback_in_progress fallback_in_progress
fallback_original_locale
format format
object object
raise raise
@ -31,26 +29,14 @@ module I18n
scope scope
separator separator
throw throw
] ].freeze
RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
EMPTY_HASH = {}.freeze EMPTY_HASH = {}.freeze
def self.new_double_nested_cache # :nodoc: def self.new_double_nested_cache # :nodoc:
Concurrent::Map.new { |h, k| h[k] = Concurrent::Map.new } Concurrent::Map.new { |h, k| h[k] = Concurrent::Map.new }
end end
# Marks a key as reserved. Reserved keys are used internally,
# and can't also be used for interpolation. If you are using any
# extra keys as I18n options, you should call I18n.reserve_key
# before any I18n.translate (etc) calls are made.
def self.reserve_key(key)
RESERVED_KEYS << key.to_sym
@reserved_keys_pattern = nil
end
def self.reserved_keys_pattern # :nodoc:
@reserved_keys_pattern ||= /%\{(#{RESERVED_KEYS.join("|")})\}/
end
module Base module Base
# Gets I18n configuration object. # Gets I18n configuration object.
def config def config
@ -274,14 +260,14 @@ module I18n
# #
# Setting a Hash using Ruby: # Setting a Hash using Ruby:
# #
# store_translations(:de, i18n: { # store_translations(:de, :i18n => {
# transliterate: { # :transliterate => {
# rule: { # :rule => {
# 'ü' => 'ue', # "ü" => "ue",
# 'ö' => 'oe' # "ö" => "oe"
# } # }
# } # }
# }) # )
# #
# Setting a Proc: # Setting a Proc:
# #
@ -410,7 +396,7 @@ module I18n
keys.delete('') keys.delete('')
keys.map! do |k| keys.map! do |k|
case k case k
when /\A[-+]?([1-9]\d*|0)\z/ # integer when /\A[-+]?[1-9]\d*\z/ # integer
k.to_i k.to_i
when 'true' when 'true'
true true

View File

@ -2,10 +2,12 @@
require 'yaml' require 'yaml'
require 'json' require 'json'
require 'i18n/core_ext/hash'
module I18n module I18n
module Backend module Backend
module Base module Base
using I18n::HashRefinements
include I18n::Backend::Transliterator include I18n::Backend::Transliterator
# Accepts a list of paths to translation files. Loads translations from # Accepts a list of paths to translation files. Loads translations from
@ -51,7 +53,7 @@ module I18n
end end
deep_interpolation = options[:deep_interpolation] deep_interpolation = options[:deep_interpolation]
values = Utils.except(options, *RESERVED_KEYS) values = options.except(*RESERVED_KEYS)
if values if values
entry = if deep_interpolation entry = if deep_interpolation
deep_interpolate(locale, entry, values) deep_interpolate(locale, entry, values)
@ -221,18 +223,17 @@ module I18n
def load_file(filename) def load_file(filename)
type = File.extname(filename).tr('.', '').downcase type = File.extname(filename).tr('.', '').downcase
raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true) raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true)
data, keys_symbolized = send(:"load_#{type}", filename) data = send(:"load_#{type}", filename)
unless data.is_a?(Hash) unless data.is_a?(Hash)
raise InvalidLocaleData.new(filename, 'expects it to return a hash, but does not') raise InvalidLocaleData.new(filename, 'expects it to return a hash, but does not')
end end
data.each { |locale, d| store_translations(locale, d || {}, skip_symbolize_keys: keys_symbolized) } data.each { |locale, d| store_translations(locale, d || {}) }
end end
# Loads a plain Ruby translations file. eval'ing the file must yield # Loads a plain Ruby translations file. eval'ing the file must yield
# a Hash containing translation data with locales as toplevel keys. # a Hash containing translation data with locales as toplevel keys.
def load_rb(filename) def load_rb(filename)
translations = eval(IO.read(filename), binding, filename) eval(IO.read(filename), binding, filename)
[translations, false]
end end
# Loads a YAML translations file. The data must have locales as # Loads a YAML translations file. The data must have locales as
@ -240,9 +241,9 @@ module I18n
def load_yml(filename) def load_yml(filename)
begin begin
if YAML.respond_to?(:unsafe_load_file) # Psych 4.0 way if YAML.respond_to?(:unsafe_load_file) # Psych 4.0 way
[YAML.unsafe_load_file(filename, symbolize_names: true, freeze: true), true] YAML.unsafe_load_file(filename)
else else
[YAML.load_file(filename), false] YAML.load_file(filename)
end end
rescue TypeError, ScriptError, StandardError => e rescue TypeError, ScriptError, StandardError => e
raise InvalidLocaleData.new(filename, e.inspect) raise InvalidLocaleData.new(filename, e.inspect)
@ -254,12 +255,7 @@ module I18n
# toplevel keys. # toplevel keys.
def load_json(filename) def load_json(filename)
begin begin
# Use #load_file as a proxy for a version of JSON where symbolize_names and freeze are supported. ::JSON.parse(File.read(filename))
if ::JSON.respond_to?(:load_file)
[::JSON.load_file(filename, symbolize_names: true, freeze: true), true]
else
[::JSON.parse(File.read(filename)), false]
end
rescue TypeError, StandardError => e rescue TypeError, StandardError => e
raise InvalidLocaleData.new(filename, e.inspect) raise InvalidLocaleData.new(filename, e.inspect)
end end

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'i18n/core_ext/hash'
module I18n module I18n
module Backend module Backend
# Backend that chains multiple other backends and checks each of them when # Backend that chains multiple other backends and checks each of them when
@ -19,6 +17,8 @@ module I18n
# The implementation assumes that all backends added to the Chain implement # The implementation assumes that all backends added to the Chain implement
# a lookup method with the same API as Simple backend does. # a lookup method with the same API as Simple backend does.
class Chain class Chain
using I18n::HashRefinements
module Implementation module Implementation
include Base include Base
@ -55,7 +55,7 @@ module I18n
def translate(locale, key, default_options = EMPTY_HASH) def translate(locale, key, default_options = EMPTY_HASH)
namespace = nil namespace = nil
options = Utils.except(default_options, :default) options = default_options.except(:default)
backends.each do |backend| backends.each do |backend|
catch(:exception) do catch(:exception) do
@ -101,7 +101,7 @@ module I18n
init_translations unless initialized? init_translations unless initialized?
translations translations
end end
Utils.deep_merge!(memo, partial_translations) { |_, a, b| b || a } memo.deep_merge!(partial_translations) { |_, a, b| b || a }
end end
end end

View File

@ -43,7 +43,7 @@ module I18n
return super if options[:fallback_in_progress] return super if options[:fallback_in_progress]
default = extract_non_symbol_default!(options) if options[:default] default = extract_non_symbol_default!(options) if options[:default]
fallback_options = options.merge(:fallback_in_progress => true, fallback_original_locale: locale) fallback_options = options.merge(:fallback_in_progress => true)
I18n.fallbacks[locale].each do |fallback| I18n.fallbacks[locale].each do |fallback|
begin begin
catch(:exception) do catch(:exception) do
@ -64,17 +64,6 @@ module I18n
throw(:exception, I18n::MissingTranslation.new(locale, key, options)) throw(:exception, I18n::MissingTranslation.new(locale, key, options))
end end
def resolve(locale, object, subject, options = EMPTY_HASH)
return subject if options[:resolve] == false
return super unless subject.is_a?(Symbol)
result = catch(:exception) do
options.delete(:fallback_in_progress)
I18n.translate(subject, **options.merge(locale: options[:fallback_original_locale], throw: true))
end
result unless result.is_a?(MissingTranslation)
end
def extract_non_symbol_default!(options) def extract_non_symbol_default!(options)
defaults = [options[:default]].flatten defaults = [options[:default]].flatten
first_non_symbol_default = defaults.detect{|default| !default.is_a?(Symbol)} first_non_symbol_default = defaults.detect{|default| !default.is_a?(Symbol)}

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'i18n/core_ext/hash'
require 'i18n/gettext' require 'i18n/gettext'
require 'i18n/gettext/po_parser' require 'i18n/gettext/po_parser'
@ -32,6 +31,8 @@ module I18n
# Without it strings containing periods (".") will not be translated. # Without it strings containing periods (".") will not be translated.
module Gettext module Gettext
using I18n::HashRefinements
class PoData < Hash class PoData < Hash
def set_comment(msgid_or_sym, comment) def set_comment(msgid_or_sym, comment)
# ignore # ignore
@ -42,7 +43,7 @@ module I18n
def load_po(filename) def load_po(filename)
locale = ::File.basename(filename, '.po').to_sym locale = ::File.basename(filename, '.po').to_sym
data = normalize(locale, parse(filename)) data = normalize(locale, parse(filename))
[{ locale => data }, false] { locale => data }
end end
def parse(filename) def parse(filename)
@ -60,7 +61,7 @@ module I18n
{ part => _normalized.empty? ? value : _normalized } { part => _normalized.empty? ? value : _normalized }
end end
Utils.deep_merge!(result, normalized) result.deep_merge!(normalized)
end end
result result
end end

View File

@ -67,6 +67,8 @@ module I18n
# #
# This is useful if you are using a KeyValue backend chained to a Simple backend. # This is useful if you are using a KeyValue backend chained to a Simple backend.
class KeyValue class KeyValue
using I18n::HashRefinements
module Implementation module Implementation
attr_accessor :store attr_accessor :store
@ -89,7 +91,7 @@ module I18n
when Hash when Hash
if @subtrees && (old_value = @store[key]) if @subtrees && (old_value = @store[key])
old_value = JSON.decode(old_value) old_value = JSON.decode(old_value)
value = Utils.deep_merge!(Utils.deep_symbolize_keys(old_value), value) if old_value.is_a?(Hash) value = old_value.deep_symbolize_keys.deep_merge!(value) if old_value.is_a?(Hash)
end end
when Proc when Proc
raise "Key-value stores cannot handle procs" raise "Key-value stores cannot handle procs"
@ -113,12 +115,12 @@ module I18n
# them into a hash such as the one returned from loading the # them into a hash such as the one returned from loading the
# haml files # haml files
def translations def translations
@translations = Utils.deep_symbolize_keys(@store.keys.clone.map do |main_key| @translations = @store.keys.clone.map do |main_key|
main_value = JSON.decode(@store[main_key]) main_value = JSON.decode(@store[main_key])
main_key.to_s.split(".").reverse.inject(main_value) do |value, key| main_key.to_s.split(".").reverse.inject(main_value) do |value, key|
{key.to_sym => value} {key.to_sym => value}
end end
end.inject{|hash, elem| Utils.deep_merge!(hash, elem)}) end.inject{|hash, elem| hash.deep_merge!(elem)}.deep_symbolize_keys
end end
def init_translations def init_translations
@ -139,7 +141,7 @@ module I18n
value = JSON.decode(value) if value value = JSON.decode(value) if value
if value.is_a?(Hash) if value.is_a?(Hash)
Utils.deep_symbolize_keys(value) value.deep_symbolize_keys
elsif !value.nil? elsif !value.nil?
value value
elsif !@subtrees elsif !@subtrees

View File

@ -19,6 +19,8 @@ module I18n
# #
# I18n::Backend::Simple.include(I18n::Backend::Pluralization) # I18n::Backend::Simple.include(I18n::Backend::Pluralization)
class Simple class Simple
using I18n::HashRefinements
module Implementation module Implementation
include Base include Base
@ -38,8 +40,8 @@ module I18n
end end
locale = locale.to_sym locale = locale.to_sym
translations[locale] ||= Concurrent::Hash.new translations[locale] ||= Concurrent::Hash.new
data = Utils.deep_symbolize_keys(data) unless options.fetch(:skip_symbolize_keys, false) data = data.deep_symbolize_keys
Utils.deep_merge!(translations[locale], data) translations[locale].deep_merge!(data)
end end
# Get available locales from the translations hash # Get available locales from the translations hash

View File

@ -0,0 +1,59 @@
module I18n
module HashRefinements
refine Hash do
using I18n::HashRefinements
def except(*keys)
dup.except!(*keys)
end unless method_defined?(:except)
def except!(*keys)
keys.each { |key| delete(key) }
self
end
def deep_symbolize_keys
each_with_object({}) do |(key, value), result|
result[symbolize_key(key)] = deep_symbolize_keys_in_object(value)
result
end
end
# deep_merge from activesupport 5
# Copyright (c) 2005-2019 David Heinemeier Hansson
def deep_merge(other_hash, &block)
dup.deep_merge!(other_hash, &block)
end
# deep_merge! from activesupport 5
# Copyright (c) 2005-2019 David Heinemeier Hansson
def deep_merge!(other_hash, &block)
merge!(other_hash) do |key, this_val, other_val|
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
this_val.deep_merge(other_val, &block)
elsif block_given?
block.call(key, this_val, other_val)
else
other_val
end
end
end
def symbolize_key(key)
key.respond_to?(:to_sym) ? key.to_sym : key
end
private
def deep_symbolize_keys_in_object(value)
case value
when Hash
value.deep_symbolize_keys
when Array
value.map { |e| deep_symbolize_keys_in_object(e) }
else
value
end
end
end
end
end

View File

@ -47,12 +47,10 @@ module I18n
class MissingTranslation < ArgumentError class MissingTranslation < ArgumentError
module Base module Base
PERMITTED_KEYS = [:scope].freeze
attr_reader :locale, :key, :options attr_reader :locale, :key, :options
def initialize(locale, key, options = EMPTY_HASH) def initialize(locale, key, options = EMPTY_HASH)
@key, @locale, @options = key, locale, options.slice(*PERMITTED_KEYS) @key, @locale, @options = key, locale, options.dup
options.each { |k, v| self.options[k] = v.inspect if v.is_a?(Proc) } options.each { |k, v| self.options[k] = v.inspect if v.is_a?(Proc) }
end end

View File

@ -5,7 +5,7 @@ module I18n
DEFAULT_INTERPOLATION_PATTERNS = [ DEFAULT_INTERPOLATION_PATTERNS = [
/%%/, /%%/,
/%\{([\w|]+)\}/, # matches placeholders like "%{foo} or %{foo|word}" /%\{([\w|]+)\}/, # matches placeholders like "%{foo} or %{foo|word}"
/%<(\w+)>([^\d]*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d" /%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
].freeze ].freeze
INTERPOLATION_PATTERN = Regexp.union(DEFAULT_INTERPOLATION_PATTERNS) INTERPOLATION_PATTERN = Regexp.union(DEFAULT_INTERPOLATION_PATTERNS)
deprecate_constant :INTERPOLATION_PATTERN deprecate_constant :INTERPOLATION_PATTERN
@ -14,7 +14,7 @@ module I18n
# Return String or raises MissingInterpolationArgument exception. # Return String or raises MissingInterpolationArgument exception.
# Missing argument's logic is handled by I18n.config.missing_interpolation_argument_handler. # Missing argument's logic is handled by I18n.config.missing_interpolation_argument_handler.
def interpolate(string, values) def interpolate(string, values)
raise ReservedInterpolationKey.new($1.to_sym, string) if string =~ I18n.reserved_keys_pattern raise ReservedInterpolationKey.new($1.to_sym, string) if string =~ RESERVED_KEYS_PATTERN
raise ArgumentError.new('Interpolation values must be a Hash.') unless values.kind_of?(Hash) raise ArgumentError.new('Interpolation values must be a Hash.') unless values.kind_of?(Hash)
interpolate_hash(string, values) interpolate_hash(string, values)
end end

View File

@ -15,12 +15,19 @@
# * all parent locales of a given locale (e.g. :es for :"es-MX") first, # * all parent locales of a given locale (e.g. :es for :"es-MX") first,
# * the current default locales and all of their parents second # * the current default locales and all of their parents second
# #
# The default locales are set to [] by default but can be set to something else. # The default locales are set to [I18n.default_locale] by default but can be
# set to something else.
# #
# One can additionally add any number of additional fallback locales manually. # One can additionally add any number of additional fallback locales manually.
# These will be added before the default locales to the fallback chain. For # These will be added before the default locales to the fallback chain. For
# example: # example:
# #
# # using the default locale as default fallback locale
#
# I18n.default_locale = :"en-US"
# I18n.fallbacks = I18n::Locale::Fallbacks.new(:"de-AT" => :"de-DE")
# I18n.fallbacks[:"de-AT"] # => [:"de-AT", :de, :"de-DE"]
#
# # using a custom locale as default fallback locale # # using a custom locale as default fallback locale
# #
# I18n.fallbacks = I18n::Locale::Fallbacks.new(:"en-GB", :"de-AT" => :de, :"de-CH" => :de) # I18n.fallbacks = I18n::Locale::Fallbacks.new(:"en-GB", :"de-AT" => :de, :"de-CH" => :de)
@ -64,18 +71,13 @@ module I18n
super || store(locale, compute(locale)) super || store(locale, compute(locale))
end end
def map(*args, &block) def map(mappings)
if args.count == 1 && !block_given? mappings.each do |from, to|
mappings = args.first from, to = from.to_sym, Array(to)
mappings.each do |from, to| to.each do |_to|
from, to = from.to_sym, Array(to) @map[from] ||= []
to.each do |_to| @map[from] << _to.to_sym
@map[from] ||= []
@map[from] << _to.to_sym
end
end end
else
@map.map(*args, &block)
end end
end end

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module I18n module I18n
VERSION = "1.9.0" VERSION = "1.8.11"
end end

View File

@ -1,55 +0,0 @@
# frozen_string_literal: true
module I18n
module Utils
class << self
if Hash.method_defined?(:except)
def except(hash, *keys)
hash.except(*keys)
end
else
def except(hash, *keys)
hash = hash.dup
keys.each { |k| hash.delete(k) }
hash
end
end
def deep_merge(hash, other_hash, &block)
deep_merge!(hash.dup, other_hash, &block)
end
def deep_merge!(hash, other_hash, &block)
hash.merge!(other_hash) do |key, this_val, other_val|
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
deep_merge(this_val, other_val, &block)
elsif block_given?
yield key, this_val, other_val
else
other_val
end
end
end
def deep_symbolize_keys(hash)
hash.each_with_object({}) do |(key, value), result|
result[key.respond_to?(:to_sym) ? key.to_sym : key] = deep_symbolize_keys_in_object(value)
result
end
end
private
def deep_symbolize_keys_in_object(value)
case value
when Hash
deep_symbolize_keys(value)
when Array
value.map { |e| deep_symbolize_keys_in_object(e) }
else
value
end
end
end
end
end