Class: I18n::Locale::Fallbacks

Inherits:
Hash
  • Object
show all
Defined in:
lib/vendor/i18n/lib/i18n/locale/fallbacks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*mappings) ⇒ Fallbacks

Returns a new instance of Fallbacks.



60
61
62
63
64
# File 'lib/vendor/i18n/lib/i18n/locale/fallbacks.rb', line 60

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

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



69
70
71
# File 'lib/vendor/i18n/lib/i18n/locale/fallbacks.rb', line 69

def defaults
  @defaults
end

Instance Method Details

#[](locale) ⇒ Object

Raises:



71
72
73
74
75
# File 'lib/vendor/i18n/lib/i18n/locale/fallbacks.rb', line 71

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

#map(mappings) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/vendor/i18n/lib/i18n/locale/fallbacks.rb', line 77

def map(mappings)
  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
end