Files
nairobi/app/helpers/site_customization_helper.rb
2018-11-05 18:20:50 +01:00

31 lines
930 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)
i18n_content = I18nContent.where(key: content.key).first
if i18n_content.present?
I18nContentTranslation.where(
i18n_content_id: i18n_content.id,
locale: locale
).first.try(:value)
else
false
end
end
def merge_translatable_field_options(options, locale)
options.merge(
class: "#{options[:class]} js-globalize-attribute".strip,
style: "#{options[:style]} #{site_customization_display_translation_style(locale)}".strip,
data: (options[:data] || {}).merge(locale: locale)
)
end
end