Class: I18n::Locale::Fallbacks

Inherits:
Hash show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/locale/fallbacks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#as_json, #assert_valid_keys, #compact_blank, #compact_blank!, #deep_dup, #deep_merge, #deep_merge!, #deep_stringify_keys, #deep_stringify_keys!, #deep_symbolize_keys, #deep_symbolize_keys!, #deep_transform_keys, #deep_transform_keys!, #deep_transform_values, #deep_transform_values!, #except, #except!, #extract!, #extractable_options?, from_trusted_xml, from_xml, #reverse_merge, #reverse_merge!, #slice!, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_query, #to_xml, #with_indifferent_access

Constructor Details

#initialize(*mappings) ⇒ Fallbacks

Returns a new instance of Fallbacks.



49
50
51
52
53
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/locale/fallbacks.rb', line 49

def initialize(*mappings)
  @map = {}
  map(mappings.pop) if mappings.last.is_a?(Hash)
  self.defaults = mappings.empty? ? [] : mappings
end

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



58
59
60
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/locale/fallbacks.rb', line 58

def defaults
  @defaults
end

Instance Method Details

#[](locale) ⇒ Object

Raises:



60
61
62
63
64
65
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/locale/fallbacks.rb', line 60

def [](locale)
  raise InvalidLocale.new(locale) if locale.nil?
  raise Disabled.new('fallback#[]') if locale == false
  locale = locale.to_sym
  super || store(locale, compute(locale))
end

#map(*args, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/locale/fallbacks.rb', line 67

def map(*args, &block)
  if args.count == 1 && !block_given?
    mappings = args.first
    mappings.each do |from, to|
      from, to = from.to_sym, Array(to)
      to.each do |_to|
        @map[from] ||= []
        @map[from] << _to.to_sym
      end
    end
  else
    @map.map(*args, &block)
  end
end