brew vendor-gems: commit updates.
This commit is contained in:
parent
72a6f7668c
commit
244a4c646e
@ -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.8.11/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/i18n-1.9.1/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"
|
||||||
|
|||||||
@ -1,59 +0,0 @@
|
|||||||
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
|
|
||||||
@ -4,6 +4,7 @@ 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'
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ module I18n
|
|||||||
exception_handler
|
exception_handler
|
||||||
fallback
|
fallback
|
||||||
fallback_in_progress
|
fallback_in_progress
|
||||||
|
fallback_original_locale
|
||||||
format
|
format
|
||||||
object
|
object
|
||||||
raise
|
raise
|
||||||
@ -29,14 +31,26 @@ 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
|
||||||
@ -260,14 +274,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:
|
||||||
#
|
#
|
||||||
@ -396,7 +410,7 @@ module I18n
|
|||||||
keys.delete('')
|
keys.delete('')
|
||||||
keys.map! do |k|
|
keys.map! do |k|
|
||||||
case k
|
case k
|
||||||
when /\A[-+]?[1-9]\d*\z/ # integer
|
when /\A[-+]?([1-9]\d*|0)\z/ # integer
|
||||||
k.to_i
|
k.to_i
|
||||||
when 'true'
|
when 'true'
|
||||||
true
|
true
|
||||||
@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
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
|
||||||
@ -53,7 +51,7 @@ module I18n
|
|||||||
end
|
end
|
||||||
|
|
||||||
deep_interpolation = options[:deep_interpolation]
|
deep_interpolation = options[:deep_interpolation]
|
||||||
values = options.except(*RESERVED_KEYS)
|
values = Utils.except(options, *RESERVED_KEYS)
|
||||||
if values
|
if values
|
||||||
entry = if deep_interpolation
|
entry = if deep_interpolation
|
||||||
deep_interpolate(locale, entry, values)
|
deep_interpolate(locale, entry, values)
|
||||||
@ -223,17 +221,18 @@ 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 = send(:"load_#{type}", filename)
|
data, keys_symbolized = 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 || {}) }
|
data.each { |locale, d| store_translations(locale, d || {}, skip_symbolize_keys: keys_symbolized) }
|
||||||
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)
|
||||||
eval(IO.read(filename), binding, filename)
|
translations = 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
|
||||||
@ -241,9 +240,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)
|
[YAML.unsafe_load_file(filename, symbolize_names: true, freeze: true), true]
|
||||||
else
|
else
|
||||||
YAML.load_file(filename)
|
[YAML.load_file(filename), false]
|
||||||
end
|
end
|
||||||
rescue TypeError, ScriptError, StandardError => e
|
rescue TypeError, ScriptError, StandardError => e
|
||||||
raise InvalidLocaleData.new(filename, e.inspect)
|
raise InvalidLocaleData.new(filename, e.inspect)
|
||||||
@ -255,7 +254,12 @@ module I18n
|
|||||||
# toplevel keys.
|
# toplevel keys.
|
||||||
def load_json(filename)
|
def load_json(filename)
|
||||||
begin
|
begin
|
||||||
::JSON.parse(File.read(filename))
|
# Use #load_file as a proxy for a version of JSON where symbolize_names and freeze are supported.
|
||||||
|
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
|
||||||
@ -17,8 +17,6 @@ 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 +53,7 @@ module I18n
|
|||||||
|
|
||||||
def translate(locale, key, default_options = EMPTY_HASH)
|
def translate(locale, key, default_options = EMPTY_HASH)
|
||||||
namespace = nil
|
namespace = nil
|
||||||
options = default_options.except(:default)
|
options = Utils.except(default_options, :default)
|
||||||
|
|
||||||
backends.each do |backend|
|
backends.each do |backend|
|
||||||
catch(:exception) do
|
catch(:exception) do
|
||||||
@ -101,7 +99,7 @@ module I18n
|
|||||||
init_translations unless initialized?
|
init_translations unless initialized?
|
||||||
translations
|
translations
|
||||||
end
|
end
|
||||||
memo.deep_merge!(partial_translations) { |_, a, b| b || a }
|
Utils.deep_merge!(memo, partial_translations) { |_, a, b| b || a }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -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_options = options.merge(:fallback_in_progress => true, fallback_original_locale: locale)
|
||||||
I18n.fallbacks[locale].each do |fallback|
|
I18n.fallbacks[locale].each do |fallback|
|
||||||
begin
|
begin
|
||||||
catch(:exception) do
|
catch(:exception) do
|
||||||
@ -64,6 +64,17 @@ 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)}
|
||||||
@ -31,8 +31,6 @@ 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
|
||||||
@ -43,7 +41,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 }
|
[{ locale => data }, false]
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(filename)
|
def parse(filename)
|
||||||
@ -61,7 +59,7 @@ module I18n
|
|||||||
{ part => _normalized.empty? ? value : _normalized }
|
{ part => _normalized.empty? ? value : _normalized }
|
||||||
end
|
end
|
||||||
|
|
||||||
result.deep_merge!(normalized)
|
Utils.deep_merge!(result, normalized)
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
@ -67,8 +67,6 @@ 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
|
||||||
|
|
||||||
@ -91,7 +89,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 = old_value.deep_symbolize_keys.deep_merge!(value) if old_value.is_a?(Hash)
|
value = Utils.deep_merge!(Utils.deep_symbolize_keys(old_value), 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"
|
||||||
@ -115,12 +113,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 = @store.keys.clone.map do |main_key|
|
@translations = Utils.deep_symbolize_keys(@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| hash.deep_merge!(elem)}.deep_symbolize_keys
|
end.inject{|hash, elem| Utils.deep_merge!(hash, elem)})
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_translations
|
def init_translations
|
||||||
@ -141,7 +139,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)
|
||||||
value.deep_symbolize_keys
|
Utils.deep_symbolize_keys(value)
|
||||||
elsif !value.nil?
|
elsif !value.nil?
|
||||||
value
|
value
|
||||||
elsif !@subtrees
|
elsif !@subtrees
|
||||||
@ -19,8 +19,6 @@ 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
|
||||||
|
|
||||||
@ -40,8 +38,8 @@ module I18n
|
|||||||
end
|
end
|
||||||
locale = locale.to_sym
|
locale = locale.to_sym
|
||||||
translations[locale] ||= Concurrent::Hash.new
|
translations[locale] ||= Concurrent::Hash.new
|
||||||
data = data.deep_symbolize_keys
|
data = Utils.deep_symbolize_keys(data) unless options.fetch(:skip_symbolize_keys, false)
|
||||||
translations[locale].deep_merge!(data)
|
Utils.deep_merge!(translations[locale], data)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get available locales from the translations hash
|
# Get available locales from the translations hash
|
||||||
@ -47,10 +47,12 @@ 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.dup
|
@key, @locale, @options = key, locale, options.slice(*PERMITTED_KEYS)
|
||||||
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
|
||||||
|
|
||||||
@ -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*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
|
/%<(\w+)>([^\d]*?\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 =~ RESERVED_KEYS_PATTERN
|
raise ReservedInterpolationKey.new($1.to_sym, string) if string =~ I18n.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
|
||||||
@ -15,19 +15,12 @@
|
|||||||
# * 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 [I18n.default_locale] by default but can be
|
# The default locales are set to [] by default but can be set to something else.
|
||||||
# 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)
|
||||||
@ -71,13 +64,18 @@ module I18n
|
|||||||
super || store(locale, compute(locale))
|
super || store(locale, compute(locale))
|
||||||
end
|
end
|
||||||
|
|
||||||
def map(mappings)
|
def map(*args, &block)
|
||||||
mappings.each do |from, to|
|
if args.count == 1 && !block_given?
|
||||||
from, to = from.to_sym, Array(to)
|
mappings = args.first
|
||||||
to.each do |_to|
|
mappings.each do |from, to|
|
||||||
@map[from] ||= []
|
from, to = from.to_sym, Array(to)
|
||||||
@map[from] << _to.to_sym
|
to.each do |_to|
|
||||||
|
@map[from] ||= []
|
||||||
|
@map[from] << _to.to_sym
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
@map.map(*args, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
55
Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/i18n-1.9.1/lib/i18n/utils.rb
vendored
Normal file
55
Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/i18n-1.9.1/lib/i18n/utils.rb
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# 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
|
||||||
@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module I18n
|
module I18n
|
||||||
VERSION = "1.8.11"
|
VERSION = "1.9.1"
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user