class I18n::Config
def available_locales
Unless you explicitly set these through I18n.available_locales=
Returns an array of locales for which translations are available.
def available_locales @@available_locales ||= nil @@available_locales || backend.available_locales end
def available_locales=(locales)
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
def available_locales_initialized?
def available_locales_initialized? ( !!defined?(@@available_locales) && !!@@available_locales ) end
def available_locales_set #:nodoc:
that we can have faster lookups to do the available locales enforce check.
Caches the available locales list as both strings and symbols in a Set, so
def available_locales_set #:nodoc: @@available_locales_set ||= available_locales.inject(Set.new) do |set, locale| set << locale.to_s << locale.to_sym end end
def backend
def backend @@backend ||= Backend::Simple.new end
def backend=(backend)
def backend=(backend) @@backend = backend end
def clear_available_locales_set #:nodoc:
gets reloaded.
Clears the available locales set so it can be recomputed again after I18n
def clear_available_locales_set #:nodoc: @@available_locales_set = nil end
def default_locale
def default_locale @@default_locale ||= :en end
def default_locale=(locale)
def default_locale=(locale) I18n.enforce_available_locales!(locale) @@default_locale = locale && locale.to_sym end
def default_separator
def default_separator @@default_separator ||= '.' end
def default_separator=(separator)
def default_separator=(separator) @@default_separator = separator end
def enforce_available_locales
def enforce_available_locales @@enforce_available_locales end
def enforce_available_locales=(enforce_available_locales)
def enforce_available_locales=(enforce_available_locales) @@enforce_available_locales = enforce_available_locales end
def exception_handler
Returns the current exception handler. Defaults to an instance of
def exception_handler @@exception_handler ||= ExceptionHandler.new end
def exception_handler=(exception_handler)
def exception_handler=(exception_handler) @@exception_handler = exception_handler end
def interpolation_patterns
Returns the current interpolation patterns. Defaults to
def interpolation_patterns @@interpolation_patterns ||= I18n::DEFAULT_INTERPOLATION_PATTERNS.dup end
def interpolation_patterns=(interpolation_patterns)
E.g. using {{}} as a placeholder like "{{hello}}, world!":
patterns.
Sets the current interpolation patterns. Used to set a interpolation
def interpolation_patterns=(interpolation_patterns) @@interpolation_patterns = interpolation_patterns end
def load_path
register translation files like this:
named *.yml and contain YAML data. So for the SimpleBackend clients may
files which are either named *.rb and contain plain Ruby Hashes or are
E.g. the provided SimpleBackend accepts a list of paths to translation
backend defines acceptable sources.
Allow clients to register paths providing translation data sources. The
def load_path @@load_path ||= [] end
def load_path=(load_path)
Sets the load path instance. Custom implementations are expected to
def load_path=(load_path) @@load_path = load_path @@available_locales_set = nil backend.reload! end
def locale
The only configuration value that is not global and scoped to thread is :locale.
def locale defined?(@locale) && @locale != nil ? @locale : default_locale end
def locale=(locale)
def locale=(locale) I18n.enforce_available_locales!(locale) @locale = locale && locale.to_sym end
def missing_interpolation_argument_handler
Returns the current handler for situations when interpolation argument
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
def missing_interpolation_argument_handler=(exception_handler)
"#{key} is missing"
I18n.config.missing_interpolation_argument_handler = Proc.new do |key|
You can suppress raising an exception and return string instead:
== Example:
if you don't care about arity.
are the same as for MissingInterpolationArgument initializer. Use +Proc.new+
object that responds to #call. The arguments that will be passed to #call
Sets the missing interpolation argument handler. It can be any
def missing_interpolation_argument_handler=(exception_handler) @@missing_interpolation_argument_handler = exception_handler end