Files
nairobi/app/helpers/site_customization_helper.rb
Javi Martín 1135441cbd Simplify getting I18nContent translations
This code might be slightly slower because it performs one query per
field in the form, but I didn't notice any differences on my development
machine, and the code is now much easier to understand.
2019-05-21 13:53:39 +02:00

21 lines
551 B
Ruby

module SiteCustomizationHelper
def site_customization_enable_translation?(locale)
I18nContentTranslation.existing_languages.include?(locale) || locale == I18n.locale
end
def site_customization_display_translation_style(locale)
site_customization_enable_translation?(locale) ? "" : "display: none;"
end
def translation_for_locale(content, locale)
if content.present?
I18nContentTranslation.where(
i18n_content_id: content.id,
locale: locale
).first.try(:value)
else
false
end
end
end