Refactor method to get custom texts translations

It was a bit confusing to return `false` in the method and then handle
this case in the view.
This commit is contained in:
Javi Martín
2021-10-05 20:05:46 +02:00
parent b35c8bda4b
commit c7230e668f
2 changed files with 10 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
<% globalize(locale) do %>
<%= hidden_field_tag "contents[content_#{i18n_content.key}][id]", i18n_content.key %>
<%= text_area_tag "contents[content_#{i18n_content.key}]values[value_#{locale}]",
text || t(i18n_content.key, locale: locale),
text,
rows: 5,
class: "js-globalize-attribute",
style: site_customization_display_translation_style(locale),

View File

@@ -10,10 +10,16 @@ class Admin::SiteCustomization::InformationTexts::FormFieldComponent < Applicati
private
def text
database_text || i18n_text
end
def database_text
if i18n_content.present?
I18nContentTranslation.find_by(i18n_content_id: i18n_content.id, locale: locale)&.value
else
false
i18n_content.translations.find_by(locale: locale)&.value
end
end
def i18n_text
t(i18n_content.key, locale: locale)
end
end