Module: Mobility::Plugins::Fallbacks
- Extended by:
- Mobility::Plugin
- Defined in:
- lib/mobility/plugins/fallbacks.rb
Overview
Falls back to one or more alternative locales in case no value is defined for a given locale.
For fallbacks: true, Mobility will use an instance of I18n::Locale::Fallbacks
, but this can be configured by overriding generate_fallbacks
in the translations class.
If a hash is passed to the fallbacks
option, a new fallbacks instance will be created for the model with the hash defining additional fallbacks. To set a default value for this hash, pass this value to the plugin in your Mobility configuration.
In addition, fallbacks are disabled in certain situations. To explicitly disable fallbacks when reading and writing, you can pass the fallback: false
option to the reader method. This can be useful to determine the actual value of the translated attribute, including a possible nil
value.
The other situation where fallbacks are disabled is when the locale is specified explicitly, either by passing a ‘locale` option to the accessor or by using locale or fallthrough accessors. (See example below.)
You can also pass a locale or array of locales to the fallback
option to use that locale or locales that read, e.g. fallback: :fr
would fetch the French translation if the value in the current locale was nil
, whereas fallback: [:fr, :es]
would try French, then Spanish if the value in the current locale was nil
.
Defined Under Namespace
Modules: BackendInstanceMethods Classes: I18nFallbacks
Method Summary
Methods included from Mobility::Plugin
configure, configure_default, default, dependencies, dependencies_satisfied?, included, included_hook, initialize_hook, requires