Add translations management pages
In the admin section of the application, a new page has been added so that the admins are able to manage the selected texts for translate. The texts have been divided in different "sections", depending on the nature of themselves (budgets, polls, proposals, management, etc.). Each section has become a tab with a form associated to edit all the texts for her. When a language is added, it's added for ALL the texts in the application. That means that, if an admin adds french for debates, the french form will appear for the rest of the texts. That doesn't mean that they need to fill all the texts, only that the languages work for all of them instead of individually.
This commit is contained in:
committed by
Angel Perez
parent
4be40b9e5d
commit
c18479e3ac
@@ -0,0 +1,41 @@
|
|||||||
|
class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomization::BaseController
|
||||||
|
include Translatable
|
||||||
|
|
||||||
|
def index
|
||||||
|
@contents = I18nContent.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
content_params.each do |content|
|
||||||
|
text = I18nContent.find(content[:id])
|
||||||
|
text.update(content[:values].slice(*translation_params(content[:values])))
|
||||||
|
end
|
||||||
|
redirect_to admin_site_customization_information_texts_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def i18n_content_params
|
||||||
|
attributes = [:key, :value]
|
||||||
|
params.require(:information_texts).permit(*attributes, translation_params(params[:information_texts]))
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource_model
|
||||||
|
I18nContent
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource
|
||||||
|
resource_model.find(content_params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def content_params
|
||||||
|
params.require(:contents).values
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_translations
|
||||||
|
languages_to_delete = params[:delete_translations].select { |k, v| params[:delete_translations][k] == "1" }.keys
|
||||||
|
languages_to_delete.each do |locale|
|
||||||
|
I18nContentTranslation.destroy_all(locale: locale)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/helpers/site_customization_helper.rb
Normal file
5
app/helpers/site_customization_helper.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module SiteCustomizationHelper
|
||||||
|
def site_customization_display_translation?(locale)
|
||||||
|
I18nContentTranslation.existing_languages.include?(neutral_locale(locale)) ? "" : "display: none"
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/models/i18n_content_translation.rb
Normal file
5
app/models/i18n_content_translation.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class I18nContentTranslation < ActiveRecord::Base
|
||||||
|
def self.existing_languages
|
||||||
|
self.select(:locale).uniq.map{ |l| l.locale.to_sym }.to_a
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -237,6 +237,10 @@
|
|||||||
<li <%= "class=is-active" if controller_name == "content_blocks" %>>
|
<li <%= "class=is-active" if controller_name == "content_blocks" %>>
|
||||||
<%= link_to t("admin.menu.site_customization.content_blocks"), admin_site_customization_content_blocks_path%>
|
<%= link_to t("admin.menu.site_customization.content_blocks"), admin_site_customization_content_blocks_path%>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li <%= "class=is-active" if controller_name == "information_texts" %>>
|
||||||
|
<%= link_to t("admin.menu.site_customization.information_texts"), admin_site_customization_information_texts_path%>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<%= render "globalize_locales" %>
|
||||||
|
|
||||||
|
<%= render "form", contents: [I18nContent.debates] %>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<%= render "globalize_locales" %>
|
||||||
|
|
||||||
|
<%= render "form", contents: [I18nContent.emails] %>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<%= form_tag admin_site_customization_information_texts_path do %>
|
||||||
|
<% I18n.available_locales.each do |l| %>
|
||||||
|
<%= hidden_field_tag "delete_translations[#{l}]", 0 %>
|
||||||
|
<% end %>
|
||||||
|
<% contents.each do |group| %>
|
||||||
|
<% group.each do |content| %>
|
||||||
|
<b><%= t(content[:key]) %></b>
|
||||||
|
<% content.globalize_locales.each do |locale| %>
|
||||||
|
<%= render 'form_field', content: content, locale: locale %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<%= submit_tag "Save", class: "button" %>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<% globalize(locale) do %>
|
||||||
|
<%= hidden_field_tag "contents[content_#{content.id}][id]", content.id %>
|
||||||
|
<%= text_area_tag "contents[content_#{content.id}]values[value_#{locale}]",
|
||||||
|
content.send("value_#{locale}"),
|
||||||
|
{rows: 5,
|
||||||
|
class: "js-globalize-attribute",
|
||||||
|
style: display_translation?(locale),
|
||||||
|
data: { locale: locale }}%>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<% I18n.available_locales.each do |locale| %>
|
||||||
|
<%= link_to t("admin.milestones.form.remove_language"), "#",
|
||||||
|
id: "delete-#{neutral_locale(locale)}",
|
||||||
|
style: show_delete?(locale),
|
||||||
|
class: 'float-right delete js-delete-language',
|
||||||
|
data: { locale: neutral_locale(locale) } %>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<ul class="tabs" data-tabs id="globalize_locale">
|
||||||
|
<% I18n.available_locales.each do |locale| %>
|
||||||
|
<li class="tabs-title">
|
||||||
|
<%= link_to name_for_locale(locale), "#",
|
||||||
|
style: site_customization_display_translation?(locale),
|
||||||
|
class: "js-globalize-locale-link #{highlight_current?(locale)}",
|
||||||
|
data: { locale: neutral_locale(locale) },
|
||||||
|
remote: true %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="small-12 medium-6">
|
||||||
|
<%= select_tag :translation_locale,
|
||||||
|
options_for_locale_select,
|
||||||
|
prompt: t("admin.milestones.form.add_language"),
|
||||||
|
class: "js-globalize-locale" %>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<%= render "globalize_locales" %>
|
||||||
|
|
||||||
|
<%= render "form", contents: [I18nContent.management, I18nContent.guides] %>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<%= render "globalize_locales" %>
|
||||||
|
|
||||||
|
<%= render "form", contents: [I18nContent.devise_locales, I18nContent.devise_views, I18nContent.layouts, I18nContent.legislation] %>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<%= render "globalize_locales" %>
|
||||||
|
|
||||||
|
<%= render "form", contents: [I18nContent.budgets] %>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<%= render "globalize_locales" %>
|
||||||
|
|
||||||
|
<%= render "form", contents: [I18nContent.polls] %>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<%= render "globalize_locales" %>
|
||||||
|
|
||||||
|
<%= render "form", contents: [I18nContent.community, I18nContent.proposals] %>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<ul class="tabs" data-tabs id="information-texts-tabs">
|
||||||
|
<li class="tabs-title is-active">
|
||||||
|
<%= link_to t("admin.menu.site_customization.information_texts_menu.debates"), "#tab-debates" %>
|
||||||
|
</li>
|
||||||
|
<li class="tabs-title">
|
||||||
|
<%= link_to t("admin.menu.site_customization.information_texts_menu.proposals"), "#tab-proposals" %>
|
||||||
|
</li>
|
||||||
|
<li class="tabs-title">
|
||||||
|
<%= link_to t("admin.menu.site_customization.information_texts_menu.polls"), "#tab-polls" %>
|
||||||
|
</li>
|
||||||
|
<li class="tabs-title">
|
||||||
|
<%= link_to t("admin.menu.site_customization.information_texts_menu.participatory_budgets"), "#tab-participatory-budgets" %>
|
||||||
|
</li>
|
||||||
|
<li class="tabs-title">
|
||||||
|
<%= link_to t("admin.menu.site_customization.information_texts_menu.more_information"), "#tab-more-information" %>
|
||||||
|
</li>
|
||||||
|
<li class="tabs-title">
|
||||||
|
<%= link_to t("admin.menu.site_customization.information_texts_menu.emails"), "#tab-emails" %>
|
||||||
|
</li>
|
||||||
|
<li class="tabs-title">
|
||||||
|
<%= link_to t("admin.menu.site_customization.information_texts_menu.management"), "#tab-management" %>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<h2><%= t("admin.menu.site_customization.information_texts") %></h2>
|
||||||
|
|
||||||
|
<div class="tabs-content" data-tabs-content="information-texts-tabs" role="tablist">
|
||||||
|
<%= render 'tabs' %>
|
||||||
|
|
||||||
|
<div class="tabs-panel is-active" id="tab-debates" role="tab">
|
||||||
|
<%= render "debates" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs-panel" id="tab-proposals" role="tab">
|
||||||
|
<%= render "proposals" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs-panel" id="tab-polls" role="tab">
|
||||||
|
<%= render "polls" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs-panel" id="tab-participatory-budgets" role="tab">
|
||||||
|
<%= render "participatory_budgets" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs-panel" id="tab-more-information" role="tab">
|
||||||
|
<%= render "more_information" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs-panel" id="tab-emails" role="tab">
|
||||||
|
<%= render "emails" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs-panel" id="tab-management" role="tab">
|
||||||
|
<%= render "management" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -200,6 +200,9 @@ namespace :admin do
|
|||||||
resources :pages, except: [:show]
|
resources :pages, except: [:show]
|
||||||
resources :images, only: [:index, :update, :destroy]
|
resources :images, only: [:index, :update, :destroy]
|
||||||
resources :content_blocks, except: [:show]
|
resources :content_blocks, except: [:show]
|
||||||
|
resources :information_texts, only: [:index] do
|
||||||
|
post :update, on: :collection
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resource :homepage, controller: :homepage, only: [:show]
|
resource :homepage, controller: :homepage, only: [:show]
|
||||||
|
|||||||
Reference in New Issue
Block a user