summaryrefslogtreecommitdiff
path: root/vendor/plugins/globalize2/lib/globalize/load_path.rb
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-02-07 15:50:40 +0100
committerhukl <hukl@eight.local>2009-02-07 15:50:40 +0100
commit36a2f1f3c085dd81171cf7d8220770d4ff921ab3 (patch)
tree5ded15331b192bf428af4c94d46d1abb28ef0690 /vendor/plugins/globalize2/lib/globalize/load_path.rb
parentce9645d0092d42c7bf8781378181ffbd4ff3d088 (diff)
added globalize2 plugin as well as some modifications
which use the new translation facilities. backend mostly.
Diffstat (limited to 'vendor/plugins/globalize2/lib/globalize/load_path.rb')
-rw-r--r--vendor/plugins/globalize2/lib/globalize/load_path.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/plugins/globalize2/lib/globalize/load_path.rb b/vendor/plugins/globalize2/lib/globalize/load_path.rb
new file mode 100644
index 0000000..a49825b
--- /dev/null
+++ b/vendor/plugins/globalize2/lib/globalize/load_path.rb
@@ -0,0 +1,63 @@
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
28module 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
63end \ No newline at end of file