]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/globalize2/lib/globalize/load_path.rb
Add (dummy) pluralization data for browse.way_details.also_part_of to
[rails.git] / vendor / plugins / globalize2 / lib / globalize / load_path.rb
1 # Locale load_path and Locale loading support.
2 #
3 # To use this include the Globalize::LoadPath::I18n module to I18n like this:
4 #
5 #   I18n.send :include, Globalize::LoadPath::I18n
6 #
7 # Clients can add load_paths using:
8 #
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'
11 #
12 # And load locale data using either of:
13 #
14 #   I18n.load_locales 'en-US', 'de-DE'
15 #   I18n.load_locale 'en-US'
16
17 # This will lookup all files named like:
18 #
19 #   'path/to/dir/all.yml'
20 #   'path/to/dir/en-US.yml'
21 #   'path/to/dir/en-US/*.yml'
22 #
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.
27
28 module Globalize
29   class LoadPath < Array
30     def extensions
31       @extensions ||= ['rb', 'yml']
32     end
33     attr_writer :extensions
34   
35     def locales
36       @locales ||= ['*']
37     end
38     attr_writer :locales
39   
40     def <<(path)
41       push path
42     end
43   
44     def push(*paths)
45       super(*paths.map{|path| filenames(path) }.flatten.uniq.sort)
46     end
47   
48     protected
49   
50       def filenames(path)
51         return [path] if File.file? path
52         patterns(path).map{|pattern| Dir[pattern] }
53       end
54   
55       def patterns(path)
56         locales.map do |locale|
57           extensions.map do |extension|
58             %W(#{path}/all.#{extension} #{path}/#{locale}.#{extension} #{path}/#{locale}/**/*.#{extension})
59           end
60         end.flatten.uniq
61       end
62   end
63 end