5fe05f7fa6036f8125d8bba1e2751c5b6c0c31a5
[packages/precise/mcollective.git] / lib / mcollective / vendor / i18n / lib / i18n / config.rb
1 module I18n
2   class Config
3     # The only configuration value that is not global and scoped to thread is :locale.
4     # It defaults to the default_locale.
5     def locale
6       @locale ||= default_locale
7     end
8
9     # Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
10     def locale=(locale)
11       @locale = locale.to_sym rescue nil
12     end
13
14     # Returns the current backend. Defaults to +Backend::Simple+.
15     def backend
16       @@backend ||= Backend::Simple.new
17     end
18
19     # Sets the current backend. Used to set a custom backend.
20     def backend=(backend)
21       @@backend = backend
22     end
23
24     # Returns the current default locale. Defaults to :'en'
25     def default_locale
26       @@default_locale ||= :en
27     end
28
29     # Sets the current default locale. Used to set a custom default locale.
30     def default_locale=(locale)
31       @@default_locale = locale.to_sym rescue nil
32     end
33
34     # Returns an array of locales for which translations are available.
35     # Unless you explicitely set these through I18n.available_locales=
36     # the call will be delegated to the backend.
37     def available_locales
38       @@available_locales ||= nil
39       @@available_locales || backend.available_locales
40     end
41
42     # Sets the available locales.
43     def available_locales=(locales)
44       @@available_locales = Array(locales).map { |locale| locale.to_sym }
45       @@available_locales = nil if @@available_locales.empty?
46     end
47
48     # Returns the current default scope separator. Defaults to '.'
49     def default_separator
50       @@default_separator ||= '.'
51     end
52
53     # Sets the current default scope separator.
54     def default_separator=(separator)
55       @@default_separator = separator
56     end
57
58     # Return the current exception handler. Defaults to :default_exception_handler.
59     def exception_handler
60       @@exception_handler ||= ExceptionHandler.new
61     end
62
63     # Sets the exception handler.
64     def exception_handler=(exception_handler)
65       @@exception_handler = exception_handler
66     end
67
68     # Allow clients to register paths providing translation data sources. The
69     # backend defines acceptable sources.
70     #
71     # E.g. the provided SimpleBackend accepts a list of paths to translation
72     # files which are either named *.rb and contain plain Ruby Hashes or are
73     # named *.yml and contain YAML data. So for the SimpleBackend clients may
74     # register translation files like this:
75     #   I18n.load_path << 'path/to/locale/en.yml'
76     def load_path
77       @@load_path ||= []
78     end
79
80     # Sets the load path instance. Custom implementations are expected to
81     # behave like a Ruby Array.
82     def load_path=(load_path)
83       @@load_path = load_path
84     end
85   end
86 end