Class: I18n::Locale::Fallbacks

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*mappings) ⇒ Fallbacks

Returns a new instance of Fallbacks.



49
50
51
52
53
# File '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/i18n/locale/fallbacks.rb', line 58

def defaults
  @defaults
end

Instance Method Details

#[](locale) ⇒ Object

Raises:



60
61
62
63
64
65
# File '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

#empty?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/i18n/locale/fallbacks.rb', line 82

def empty?
  @map.empty? && @defaults.empty?
end

#inspectObject



86
87
88
# File 'lib/i18n/locale/fallbacks.rb', line 86

def inspect
 "#<#{self.class.name} @map=#{@map.inspect} @defaults=#{@defaults.inspect}>"
end

#map(*args, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File '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