Sha256: a3d511c9d777ee5f624a3a9d671c89bca3623c8edbae934425cd988d1217ff79

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

# Locale load_path and Locale loading support.
#
# To use this include the Globalize::LoadPath::I18n module to I18n like this:
#
#   I18n.send :include, Globalize::LoadPath::I18n
#
# Clients can add load_paths using:
#
#   I18n.load_path.add load_path, 'rb', 'yml'   # pass any number of extensions like this
#   I18n.load_path << 'path/to/dir'             # usage without an extension, defaults to 'yml'
#
# And load locale data using either of:
#
#   I18n.load_locales 'en-US', 'de-DE'
#   I18n.load_locale 'en-US'
# 
# This will lookup all files named like:
#
#   'path/to/dir/all.yml'
#   'path/to/dir/en-US.yml'
#   'path/to/dir/en-US/*.yml'
#
# The filenames will be passed to I18n.load_translations which delegates to 
# the backend. So the actual behaviour depends on the implementation of the
# backend. I18n::Backend::Simple will be able to read YAML and plain Ruby 
# files. See the documentation for I18n.load_translations for details.

module Globalize
  class LoadPath < Array
    def extensions
      @extensions ||= ['rb', 'yml']
    end
    attr_writer :extensions
  
    def locales
      @locales ||= ['*']
    end
    attr_writer :locales
  
    def <<(path)
      push path
    end
  
    def push(*paths)
      super(*paths.map{|path| filenames(path) }.flatten.uniq.sort)
    end
  
    protected
  
      def filenames(path)
        return [path] if File.file? path
        patterns(path).map{|pattern| Dir[pattern] }
      end
  
      def patterns(path)
        locales.map do |locale|
          extensions.map do |extension|
            %W(#{path}/all.#{extension} #{path}/#{locale}.#{extension} #{path}/#{locale}/**/*.#{extension})
          end
        end.flatten.uniq
      end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
kriss-gettext_i18n-0.2.0 vendor/globalize2/lib/globalize/load_path.rb
kriss-gettext_i18n-0.2.1 vendor/globalize2/lib/globalize/load_path.rb
kriss-gettext_i18n-0.2.2 vendor/globalize2/lib/globalize/load_path.rb
kriss-gettext_i18n-0.2.3 vendor/globalize2/lib/globalize/load_path.rb
simonmenke-globalize2-0.0.1 lib/globalize/load_path.rb
simonmenke-globalize2-0.0.4 lib/globalize/load_path.rb
simonmenke-globalize2-0.0.5 lib/globalize/load_path.rb
simonmenke-globalize2-0.0.6 lib/globalize/load_path.rb
simonmenke-simonmenke-globalize2-0.0.2 lib/globalize/load_path.rb
simonmenke-globalize2-0.0.7 lib/globalize/load_path.rb
globalize2-0.1.0 lib/globalize/load_path.rb