1 # Locale load_path and Locale loading support.
 
   3 # To use this include the Globalize::LoadPath::I18n module to I18n like this:
 
   5 #   I18n.send :include, Globalize::LoadPath::I18n
 
   7 # Clients can add load_paths using:
 
   9 #   I18n.load_path.add load_path, 'rb', 'yml'   # pass any number of extensions like this
 
  10 #   I18n.load_path << 'path/to/dir'             # usage without an extension, defaults to 'yml'
 
  12 # And load locale data using either of:
 
  14 #   I18n.load_locales 'en-US', 'de-DE'
 
  15 #   I18n.load_locale 'en-US'
 
  17 # This will lookup all files named like:
 
  19 #   'path/to/dir/all.yml'
 
  20 #   'path/to/dir/en-US.yml'
 
  21 #   'path/to/dir/en-US/*.yml'
 
  23 # The filenames will be passed to I18n.load_translations which delegates to 
 
  24 # the backend. So the actual behaviour depends on the implementation of the
 
  25 # backend. I18n::Backend::Simple will be able to read YAML and plain Ruby 
 
  26 # files. See the documentation for I18n.load_translations for details.
 
  29   class LoadPath < Array
 
  31       @extensions ||= ['rb', 'yml']
 
  33     attr_writer :extensions
 
  45       super(*paths.map{|path| filenames(path) }.flatten.uniq.sort)
 
  51         return [path] if File.file? path
 
  52         patterns(path).map{|pattern| Dir[pattern] }
 
  56         locales.map do |locale|
 
  57           extensions.map do |extension|
 
  58             %W(#{path}/all.#{extension} #{path}/#{locale}.#{extension} #{path}/#{locale}/**/*.#{extension})