Module: Mobility::Backend::Fallbacks
- Defined in:
- lib/mobility/backend/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 ‘fallbacks: false` to the reader method. This can be useful to determine the actual value of the translated attribute, including a possible nil
value.
Backend Accessors collapse
-
#read(locale, **options) ⇒ Object
Value of translation.
Instance Method Details
#read(locale, **options) ⇒ Object
Returns Value of translation.
74 75 76 77 78 79 80 |
# File 'lib/mobility/backend/fallbacks.rb', line 74 def read(locale, **) return super if [:fallbacks] == false fallbacks[locale].detect do |locale| value = super(locale) break value if value.present? end end |