Extract translation logic to helper method
This commit is contained in:
@@ -7,6 +7,19 @@ module SiteCustomizationHelper
|
|||||||
site_customization_enable_translation?(locale) ? "" : "display: none;"
|
site_customization_enable_translation?(locale) ? "" : "display: none;"
|
||||||
end
|
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)
|
def merge_translatable_field_options(options, locale)
|
||||||
options.merge(
|
options.merge(
|
||||||
class: "#{options[:class]} js-globalize-attribute".strip,
|
class: "#{options[:class]} js-globalize-attribute".strip,
|
||||||
|
|||||||
@@ -1,15 +1,6 @@
|
|||||||
<% globalize(locale) do %>
|
<% globalize(locale) do %>
|
||||||
|
|
||||||
<% i18n_content = I18nContent.where(key: content.key).first %>
|
|
||||||
<% if i18n_content.present? %>
|
|
||||||
<% i18n_content_translation = I18nContentTranslation.where(i18n_content_id: i18n_content.id, locale: locale).first.try(:value) %>
|
|
||||||
<% else %>
|
|
||||||
<% i18n_content_translation = false %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= hidden_field_tag "contents[content_#{content.key}][id]", content.key %>
|
<%= hidden_field_tag "contents[content_#{content.key}][id]", content.key %>
|
||||||
<%= text_area_tag "contents[content_#{content.key}]values[value_#{locale}]",
|
<%= text_area_tag "contents[content_#{content.key}]values[value_#{locale}]",
|
||||||
i18n_content_translation ||
|
translation_for_locale(content, locale) || t(content.key, locale: locale),
|
||||||
t(content.key, locale: locale),
|
|
||||||
merge_translatable_field_options({rows: 5}, locale) %>
|
merge_translatable_field_options({rows: 5}, locale) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user