Module: Maglev::Translatable

Extended by:
ActiveSupport::Concern
Included in:
Page, Site, StaticPage
Defined in:
app/models/concerns/maglev/translatable.rb

Defined Under Namespace

Classes: UnavailableLocaleError

Instance Method Summary collapse

Instance Method Details

#translate_attr_in(attr, locale, source_locale) ⇒ Object



15
16
17
# File 'app/models/concerns/maglev/translatable.rb', line 15

def translate_attr_in(attr, locale, source_locale)
  translations_for(attr)[locale.to_s] ||= translations_for(attr)[source_locale.to_s]
end

#translations_for(attr) ⇒ Object



10
11
12
13
# File 'app/models/concerns/maglev/translatable.rb', line 10

def translations_for(attr)
  # With MySQL, there is no default value for JSON columns, so we need to check for nil
  public_send("#{attr}_translations").presence || {}
end