1 require 'globalize/locale/language_tag'
 
   7     # Returns the current fallbacks. Defaults to +Globalize::Locale::Fallbacks+.
 
   9       @@fallbacks ||= Globalize::Locale::Fallbacks.new
 
  12     # Sets the current fallbacks. Used to set a custom fallbacks instance.
 
  13     def fallbacks=(fallbacks) 
 
  14       @@fallbacks = fallbacks
 
  21     class Fallbacks < Hash
 
  22       def initialize(*defaults)
 
  24         map defaults.pop if defaults.last.is_a?(Hash)
 
  26         defaults = [I18n.default_locale.to_sym] if defaults.empty?
 
  27         self.defaults = defaults 
 
  30       def defaults=(defaults)
 
  31         @defaults = defaults.map{|default| compute(default, false) }.flatten << :root
 
  37         has_key?(tag) ? fetch(tag) : store(tag, compute(tag))
 
  41         mappings.each do |from, to|
 
  42           from, to = from.to_sym, Array(to)
 
  45             @map[from] << to.to_sym
 
  52       def compute(tags, include_defaults = true)
 
  53         result = Array(tags).collect do |tag|
 
  54           tags = LanguageTag::tag(tag.to_sym).parents(true).map! {|t| t.to_sym }
 
  55           tags.each{|tag| tags += compute(@map[tag]) if @map[tag] }
 
  58         result.push *defaults if include_defaults