Class: Mobility::Plugins::Fallbacks
- Inherits:
-
Module
- Object
- Module
- Mobility::Plugins::Fallbacks
- 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 the value of
Configuration#default_fallbacks for the fallbacks instance. This
defaults to an instance of I18n::Locale::Fallbacks, but can be configured
(see Configuration).
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.
In addition, fallbacks can be disabled when reading by passing fallback:
false to the reader method. This can be useful to determine the actual
value of the translated attribute, including a possible nil value. 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.
Class Method Summary collapse
-
.apply(attributes, option) ⇒ Object
Applies fallbacks plugin to attributes.
Instance Method Summary collapse
-
#initialize(fallbacks_option) ⇒ Fallbacks
constructor
A new instance of Fallbacks.
Constructor Details
#initialize(fallbacks_option) ⇒ Fallbacks
Returns a new instance of Fallbacks.
88 89 90 |
# File 'lib/mobility/plugins/fallbacks.rb', line 88 def initialize(fallbacks_option) define_read(convert_option_to_fallbacks(fallbacks_option)) end |
Class Method Details
.apply(attributes, option) ⇒ Object
Applies fallbacks plugin to attributes.
84 85 86 |
# File 'lib/mobility/plugins/fallbacks.rb', line 84 def self.apply(attributes, option) attributes.backend_class.include(new(option)) unless option == false end |