Extract translation helper from translatable form views
So that individual form partials don't depend on the implementation of how translations are deleted.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
<div class="row">
|
||||
<% date_started_at = @banner.post_started_at.present? ? I18n.localize(@banner.post_started_at) : "" %>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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| %>
|
||||
|
||||
Reference in New Issue
Block a user