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"
|
same_locale?(neutral_locale(I18n.locale), neutral_locale(locale)) ? "" : "display: none"
|
||||||
end
|
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)
|
def css_to_display_translation?(resource, locale)
|
||||||
resource.translated_locales.include?(neutral_locale(locale)) || locale == I18n.locale ? "" : "display: none"
|
resource.translated_locales.include?(neutral_locale(locale)) || locale == I18n.locale ? "" : "display: none"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
module SiteCustomizationHelper
|
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)
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
<%= render 'errors' %>
|
<%= render 'errors' %>
|
||||||
|
|
||||||
<% @banner.globalize_locales.each do |locale| %>
|
<%= render_translations_to_delete(@banner) %>
|
||||||
<%= hidden_field_tag "delete_translations[#{locale}]", 0 %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% date_started_at = @banner.post_started_at.present? ? I18n.localize(@banner.post_started_at) : "" %>
|
<% 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| %>
|
<%= form_for [:admin, @investment.budget, @investment, @milestone] do |f| %>
|
||||||
|
|
||||||
|
<%= render_translations_to_delete(@milestone) %>
|
||||||
|
|
||||||
<%= f.hidden_field :title, value: l(Time.current, format: :datetime),
|
<%= f.hidden_field :title, value: l(Time.current, format: :datetime),
|
||||||
maxlength: Budget::Investment::Milestone.title_max_length %>
|
maxlength: Budget::Investment::Milestone.title_max_length %>
|
||||||
|
|
||||||
@@ -16,7 +18,6 @@
|
|||||||
|
|
||||||
<%= f.label :description, t("admin.milestones.new.description") %>
|
<%= f.label :description, t("admin.milestones.new.description") %>
|
||||||
<% @milestone.globalize_locales.each do |locale| %>
|
<% @milestone.globalize_locales.each do |locale| %>
|
||||||
<%= hidden_field_tag "delete_translations[#{locale}]", 0 %>
|
|
||||||
<% globalize(locale) do %>
|
<% globalize(locale) do %>
|
||||||
<%= f.text_area "description_#{locale}", rows: 5,
|
<%= f.text_area "description_#{locale}", rows: 5,
|
||||||
class: "js-globalize-attribute",
|
class: "js-globalize-attribute",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<%= form_tag admin_site_customization_information_texts_path do %>
|
<%= form_tag admin_site_customization_information_texts_path do %>
|
||||||
<% I18n.available_locales.each do |l| %>
|
<% I18n.available_locales.each do |l| %>
|
||||||
<%= hidden_field_tag "delete_translations[#{l}]", 0 %>
|
<%= translation_enabled_tag l, site_customization_enable_translation?(l) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% contents.each do |group| %>
|
<% contents.each do |group| %>
|
||||||
<% group.each do |content| %>
|
<% group.each do |content| %>
|
||||||
|
|||||||
Reference in New Issue
Block a user