diff --git a/app/helpers/globalize_helper.rb b/app/helpers/globalize_helper.rb index b64c1ff09..fac263a1b 100644 --- a/app/helpers/globalize_helper.rb +++ b/app/helpers/globalize_helper.rb @@ -14,6 +14,18 @@ module GlobalizeHelper same_locale?(neutral_locale(I18n.locale), neutral_locale(locale)) ? "" : "display: none" end + def render_translations_to_delete(resource) + capture do + resource.globalize_locales.each do |locale| + concat translation_enabled_tag(locale, enable_locale?(resource, locale)) + end + end + end + + def translation_enabled_tag(locale, enabled) + hidden_field_tag("enabled_translations[#{locale}]", (enabled ? 1 : 0)) + end + def css_to_display_translation?(resource, locale) resource.translated_locales.include?(neutral_locale(locale)) || locale == I18n.locale ? "" : "display: none" end diff --git a/app/helpers/site_customization_helper.rb b/app/helpers/site_customization_helper.rb index d9318fd9b..9e54fbf4e 100644 --- a/app/helpers/site_customization_helper.rb +++ b/app/helpers/site_customization_helper.rb @@ -1,5 +1,9 @@ module SiteCustomizationHelper + def site_customization_enable_translation?(locale) + I18nContentTranslation.existing_languages.include?(neutral_locale(locale)) || locale == I18n.locale + end + def site_customization_display_translation?(locale) - I18nContentTranslation.existing_languages.include?(neutral_locale(locale)) || locale == I18n.locale ? "" : "display: none" + site_customization_enable_translation?(locale) ? "" : "display: none" end end diff --git a/app/views/admin/banners/_form.html.erb b/app/views/admin/banners/_form.html.erb index 495cc5e8a..105a872fb 100644 --- a/app/views/admin/banners/_form.html.erb +++ b/app/views/admin/banners/_form.html.erb @@ -4,9 +4,7 @@ <%= render 'errors' %> - <% @banner.globalize_locales.each do |locale| %> - <%= hidden_field_tag "delete_translations[#{locale}]", 0 %> - <% end %> + <%= render_translations_to_delete(@banner) %>
<% date_started_at = @banner.post_started_at.present? ? I18n.localize(@banner.post_started_at) : "" %> diff --git a/app/views/admin/budget_investment_milestones/_form.html.erb b/app/views/admin/budget_investment_milestones/_form.html.erb index d39c736dd..5598a51cd 100644 --- a/app/views/admin/budget_investment_milestones/_form.html.erb +++ b/app/views/admin/budget_investment_milestones/_form.html.erb @@ -2,6 +2,8 @@ <%= form_for [:admin, @investment.budget, @investment, @milestone] do |f| %> + <%= render_translations_to_delete(@milestone) %> + <%= f.hidden_field :title, value: l(Time.current, format: :datetime), maxlength: Budget::Investment::Milestone.title_max_length %> @@ -16,7 +18,6 @@ <%= f.label :description, t("admin.milestones.new.description") %> <% @milestone.globalize_locales.each do |locale| %> - <%= hidden_field_tag "delete_translations[#{locale}]", 0 %> <% globalize(locale) do %> <%= f.text_area "description_#{locale}", rows: 5, class: "js-globalize-attribute", diff --git a/app/views/admin/site_customization/information_texts/_form.html.erb b/app/views/admin/site_customization/information_texts/_form.html.erb index 861315691..f31aa17f4 100644 --- a/app/views/admin/site_customization/information_texts/_form.html.erb +++ b/app/views/admin/site_customization/information_texts/_form.html.erb @@ -2,7 +2,7 @@ <%= form_tag admin_site_customization_information_texts_path do %> <% I18n.available_locales.each do |l| %> - <%= hidden_field_tag "delete_translations[#{l}]", 0 %> + <%= translation_enabled_tag l, site_customization_enable_translation?(l) %> <% end %> <% contents.each do |group| %> <% group.each do |content| %>