Class: I18n::Config
- Inherits:
-
Object
- Object
- I18n::Config
- Defined in:
- lib/i18n/config.rb
Instance Method Summary (collapse)
-
- (Object) available_locales
Returns an array of locales for which translations are available.
-
- (Object) available_locales=(locales)
Sets the available locales.
-
- (Object) backend
Returns the current backend.
-
- (Object) backend=(backend)
Sets the current backend.
-
- (Object) default_locale
Returns the current default locale.
-
- (Object) default_locale=(locale)
Sets the current default locale.
-
- (Object) default_separator
Returns the current default scope separator.
-
- (Object) default_separator=(separator)
Sets the current default scope separator.
-
- (Object) exception_handler
Return the current exception handler.
-
- (Object) exception_handler=(exception_handler)
Sets the exception handler.
-
- (Object) load_path
Allow clients to register paths providing translation data sources.
-
- (Object) load_path=(load_path)
Sets the load path instance.
-
- (Object) locale
The only configuration value that is not global and scoped to thread is :locale.
-
- (Object) locale=(locale)
Sets the current locale pseudo-globally, i.e.
-
- (Object) missing_interpolation_argument_handler
Return the current handler for situations when interpolation argument is missing.
-
- (Object) missing_interpolation_argument_handler=(exception_handler)
Sets the missing interpolation argument handler.
Instance Method Details
- (Object) available_locales
Returns an array of locales for which translations are available. Unless you explicitely set these through I18n.available_locales= the call will be delegated to the backend.
37 38 39 40 |
# File 'lib/i18n/config.rb', line 37 def available_locales @@available_locales ||= nil @@available_locales || backend.available_locales end |
- (Object) available_locales=(locales)
Sets the available locales.
43 44 45 46 |
# File 'lib/i18n/config.rb', line 43 def available_locales=(locales) @@available_locales = Array(locales).map { |locale| locale.to_sym } @@available_locales = nil if @@available_locales.empty? end |
- (Object) backend
Returns the current backend. Defaults to Backend::Simple.
15 16 17 |
# File 'lib/i18n/config.rb', line 15 def backend @@backend ||= Backend::Simple.new end |
- (Object) backend=(backend)
Sets the current backend. Used to set a custom backend.
20 21 22 |
# File 'lib/i18n/config.rb', line 20 def backend=(backend) @@backend = backend end |
- (Object) default_locale
Returns the current default locale. Defaults to :'en'
25 26 27 |
# File 'lib/i18n/config.rb', line 25 def default_locale @@default_locale ||= :en end |
- (Object) default_locale=(locale)
Sets the current default locale. Used to set a custom default locale.
30 31 32 |
# File 'lib/i18n/config.rb', line 30 def default_locale=(locale) @@default_locale = locale.to_sym rescue nil end |
- (Object) default_separator
Returns the current default scope separator. Defaults to '.'
49 50 51 |
# File 'lib/i18n/config.rb', line 49 def default_separator @@default_separator ||= '.' end |
- (Object) default_separator=(separator)
Sets the current default scope separator.
54 55 56 |
# File 'lib/i18n/config.rb', line 54 def default_separator=(separator) @@default_separator = separator end |
- (Object) exception_handler
Return the current exception handler. Defaults to :default_exception_handler.
59 60 61 |
# File 'lib/i18n/config.rb', line 59 def exception_handler @@exception_handler ||= ExceptionHandler.new end |
- (Object) exception_handler=(exception_handler)
Sets the exception handler.
64 65 66 |
# File 'lib/i18n/config.rb', line 64 def exception_handler=(exception_handler) @@exception_handler = exception_handler end |
- (Object) load_path
Allow clients to register paths providing translation data sources. The backend defines acceptable sources.
E.g. the provided SimpleBackend accepts a list of paths to translation files which are either named *.rb and contain plain Ruby Hashes or are named *.yml and contain YAML data. So for the SimpleBackend clients may register translation files like this:
I18n.load_path << 'path/to/locale/en.yml'
96 97 98 |
# File 'lib/i18n/config.rb', line 96 def load_path @@load_path ||= [] end |
- (Object) load_path=(load_path)
Sets the load path instance. Custom implementations are expected to behave like a Ruby Array.
102 103 104 |
# File 'lib/i18n/config.rb', line 102 def load_path=(load_path) @@load_path = load_path end |
- (Object) locale
The only configuration value that is not global and scoped to thread is :locale. It defaults to the default_locale.
5 6 7 |
# File 'lib/i18n/config.rb', line 5 def locale @locale ||= default_locale end |
- (Object) locale=(locale)
Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
10 11 12 |
# File 'lib/i18n/config.rb', line 10 def locale=(locale) @locale = locale.to_sym rescue nil end |
- (Object) missing_interpolation_argument_handler
Return the current handler for situations when interpolation argument is missing. Defaults to MissingInterpolationArgumentHandler, which raises an exception.
71 72 73 |
# File 'lib/i18n/config.rb', line 71 def missing_interpolation_argument_handler @@missing_interpolation_argument_handler ||= MissingInterpolationArgumentHandler.new end |
- (Object) missing_interpolation_argument_handler=(exception_handler)
Sets the missing interpolation argument handler. It can be any object that responds to #call.
Example:
You can supress raising an exception by reassigning default handler with options:
I18n.config.missing_interpolation_argument_handler =
MissingInterpolationArgumentHandler.new(raise_exception: false)
84 85 86 |
# File 'lib/i18n/config.rb', line 84 def missing_interpolation_argument_handler=(exception_handler) @@missing_interpolation_argument_handler = exception_handler end |