From 7e3f0b5c18102f9ebba41bc848ff3608e4787229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Sun, 23 Dec 2018 19:19:36 +0100 Subject: [PATCH] Add translation interface feature setting Allow to enable/disable translation interface at frontend --- app/helpers/translatable_form_helper.rb | 8 ++++++++ config/locales/en/settings.yml | 2 ++ config/locales/es/settings.yml | 2 ++ spec/features/budgets/investments_spec.rb | 15 +++++++++----- spec/features/debates_spec.rb | 25 ++++++++++++++--------- spec/features/proposals_spec.rb | 25 ++++++++++++++--------- 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index fdee3bf34..43f8cef59 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -6,6 +6,14 @@ module TranslatableFormHelper end end + def translations_interface_enabled? + Setting["feature.translation_interface"].present? || backend_translations_enabled? + end + + def backend_translations_enabled? + (controller.class.parents & [Admin, Management, Valuation]).any? + end + class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder attr_accessor :translations diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index 7af06fdad..0f497a1cf 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -116,6 +116,8 @@ en: public_stats_description: "Display public stats in the Administration panel" help_page: "Help page" help_page_description: 'Displays a Help menu that contains a page with an info section about each enabled feature. Also custom pages and menus can be created in the "Custom pages" and "Custom content blocks" sections' + translation_interface: "Translation interface" + translation_interface_description: "Displays the manual translation interface that allows users to enter their content in all application available languages. This option only affects user application forms and independently will always be active in the administration panel." valuation_comment_notification: "Valuation comment notification" valuation_comment_notification_description: "Send an email to all associated users except valuation commenter to budget investment when a new valuation comment is created" map: diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index 352e4f30d..90eda0ae4 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -116,6 +116,8 @@ es: public_stats_description: "Muestra las estadísticas públicas en el panel de Administración" help_page: "Página de ayuda" help_page_description: 'Muestra un menú Ayuda que contiene una página con una sección de información sobre cada funcionalidad habilitada. También se pueden crear páginas y menús personalizados en las secciones "Personalizar páginas" y "Personalizar bloques"' + translation_interface: "Interfaz de traducción" + translation_interface_description: "Muestra la interfaz de traducción manual permitiendo a los usuarios introducir sus contenidos en todos los idiomas disponibles de la aplicación si así lo desean. Esta opción solo afecta a las vistas de usuarios de la aplicación, en el panel de administración está activa siempre." valuation_comment_notification: "Notificar comentarios de evaluación" valuation_comment_notification_description: "Envía un email a todos los usuarios menos al que haya comentado asociados a un presupuesto participativo cuando se cree un nuevo comentario de evaluación" map: diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 2e136e041..3da6a4571 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -24,11 +24,16 @@ describe "Budget Investments" do context "Concerns" do it_behaves_like "notifiable in-app", Budget::Investment it_behaves_like "relationable", Budget::Investment - it_behaves_like "new_translatable", - "budget_investment", - "new_budget_investment_path", - %w[title], - { "description" => :ckeditor } + context "Translatable at front end" do + before do + Setting["feature.translation_interface"] = true + end + it_behaves_like "new_translatable", + "budget_investment", + "new_budget_investment_path", + %w[title], + { "description" => :ckeditor } + end end context "Load" do diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 8c58682f5..74c88f758 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -11,16 +11,21 @@ describe "Debates" do context "Concerns" do it_behaves_like "notifiable in-app", Debate it_behaves_like "relationable", Debate - it_behaves_like "new_translatable", - "debate", - "new_debate_path", - %w[title], - { "description" => :ckeditor } - it_behaves_like "edit_translatable", - "debate", - "edit_debate_path", - %w[title], - { "description" => :ckeditor } + context "Translatable at front end" do + before do + Setting["feature.translation_interface"] = true + end + it_behaves_like "new_translatable", + "debate", + "new_debate_path", + %w[title], + { "description" => :ckeditor } + it_behaves_like "edit_translatable", + "debate", + "edit_debate_path", + %w[title], + { "description" => :ckeditor } + end end scenario "Index" do diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index bfaef572c..8a8d56e8c 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -15,16 +15,21 @@ describe "Proposals" do context "Concerns" do it_behaves_like "notifiable in-app", Proposal it_behaves_like "relationable", Proposal - it_behaves_like "new_translatable", - "proposal", - "new_proposal_path", - %w[title summary], - { "description" => :ckeditor } - it_behaves_like "edit_translatable", - "proposal", - "edit_proposal_path", - %w[title summary], - { "description" => :ckeditor } + context "Translatable at front end" do + before do + Setting["feature.translation_interface"] = true + end + it_behaves_like "new_translatable", + "proposal", + "new_proposal_path", + %w[title summary], + { "description" => :ckeditor } + it_behaves_like "edit_translatable", + "proposal", + "edit_proposal_path", + %w[title summary], + { "description" => :ckeditor } + end end context "Index" do