3 # The only configuration value that is not global and scoped to thread is :locale.
4 # It defaults to the default_locale.
6 @locale ||= default_locale
9 # Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
11 @locale = locale.to_sym rescue nil
14 # Returns the current backend. Defaults to +Backend::Simple+.
16 @@backend ||= Backend::Simple.new
19 # Sets the current backend. Used to set a custom backend.
24 # Returns the current default locale. Defaults to :'en'
26 @@default_locale ||= :en
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
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.
38 @@available_locales ||= nil
39 @@available_locales || backend.available_locales
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?
48 # Returns the current default scope separator. Defaults to '.'
50 @@default_separator ||= '.'
53 # Sets the current default scope separator.
54 def default_separator=(separator)
55 @@default_separator = separator
58 # Return the current exception handler. Defaults to :default_exception_handler.
60 @@exception_handler ||= ExceptionHandler.new
63 # Sets the exception handler.
64 def exception_handler=(exception_handler)
65 @@exception_handler = exception_handler
68 # Allow clients to register paths providing translation data sources. The
69 # backend defines acceptable sources.
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'
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