class I18n::Config
Public Instance Methods
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.
# File lib/i18n/config.rb, line 42 def available_locales @@available_locales ||= nil @@available_locales || backend.available_locales end
Sets the available locales.
# File lib/i18n/config.rb, line 56 def available_locales=(locales) @@available_locales = Array(locales).map { |locale| locale.to_sym } @@available_locales = nil if @@available_locales.empty? @@available_locales_set = nil end
Returns true if the #available_locales have been initialized
# File lib/i18n/config.rb, line 63 def available_locales_initialized? ( !!defined?(@@available_locales) && !!@@available_locales ) end
Returns the current backend. Defaults to Backend::Simple
.
# File lib/i18n/config.rb, line 19 def backend @@backend ||= Backend::Simple.new end
Sets the current backend. Used to set a custom backend.
# File lib/i18n/config.rb, line 24 def backend=(backend) @@backend = backend end
Returns the current default locale. Defaults to :'en'
# File lib/i18n/config.rb, line 29 def default_locale @@default_locale ||= :en end
Sets the current default locale. Used to set a custom default locale.
# File lib/i18n/config.rb, line 34 def default_locale=(locale) I18n.enforce_available_locales!(locale) @@default_locale = locale && locale.to_sym end
Returns the current default scope separator. Defaults to '.'
# File lib/i18n/config.rb, line 74 def default_separator @@default_separator ||= '.' end
Sets the current default scope separator.
# File lib/i18n/config.rb, line 79 def default_separator=(separator) @@default_separator = separator end
# File lib/i18n/config.rb, line 140 def enforce_available_locales @@enforce_available_locales end
# File lib/i18n/config.rb, line 144 def enforce_available_locales=(enforce_available_locales) @@enforce_available_locales = enforce_available_locales end
Returns the current exception handler. Defaults to an instance of I18n::ExceptionHandler.
# File lib/i18n/config.rb, line 85 def exception_handler @@exception_handler ||= ExceptionHandler.new end
Sets the exception handler.
# File lib/i18n/config.rb, line 90 def exception_handler=(exception_handler) @@exception_handler = exception_handler end
Returns the current interpolation patterns. Defaults to I18n::DEFAULT_INTERPOLATION_PATTERNS.
# File lib/i18n/config.rb, line 150 def interpolation_patterns @@interpolation_patterns ||= I18n::DEFAULT_INTERPOLATION_PATTERNS.dup end
Sets the current interpolation patterns. Used to set a interpolation patterns.
E.g. using {{}} as a placeholder like “{{hello}}, world!”:
I18n.config.interpolation_patterns << /\{\{(\w+)\}\}/
# File lib/i18n/config.rb, line 160 def interpolation_patterns=(interpolation_patterns) @@interpolation_patterns = interpolation_patterns end
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'
# File lib/i18n/config.rb, line 125 def load_path @@load_path ||= [] end
Sets the load path instance. Custom implementations are expected to behave like a Ruby Array.
# File lib/i18n/config.rb, line 131 def load_path=(load_path) @@load_path = load_path @@available_locales_set = nil backend.reload! end
The only configuration value that is not global and scoped to thread is :locale. It defaults to the default_locale.
# File lib/i18n/config.rb, line 8 def locale defined?(@locale) && @locale != nil ? @locale : default_locale end
Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
# File lib/i18n/config.rb, line 13 def locale=(locale) I18n.enforce_available_locales!(locale) @locale = locale && locale.to_sym end
Returns the current handler for situations when interpolation argument is missing. MissingInterpolationArgument will be raised by default.
# File lib/i18n/config.rb, line 96 def missing_interpolation_argument_handler @@missing_interpolation_argument_handler ||= lambda do |missing_key, provided_hash, string| raise MissingInterpolationArgument.new(missing_key, provided_hash, string) end end
Sets the missing interpolation argument handler. It can be any object that
responds to call. The arguments that will be passed to call are the same as
for MissingInterpolationArgument
initializer. Use Proc.new
if you don't care about arity.
Example:¶ ↑
You can supress raising an exception and return string instead:
I18n.config.missing_interpolation_argument_handler = Proc.new do |key| "#{key} is missing" end
# File lib/i18n/config.rb, line 113 def missing_interpolation_argument_handler=(exception_handler) @@missing_interpolation_argument_handler = exception_handler end