diff --git a/decidim-core/app/commands/decidim/amendable/accept.rb b/decidim-core/app/commands/decidim/amendable/accept.rb index 2b6a3a1336851..e03465c04fec8 100644 --- a/decidim-core/app/commands/decidim/amendable/accept.rb +++ b/decidim-core/app/commands/decidim/amendable/accept.rb @@ -57,8 +57,20 @@ def update_amendable! visibility: "public-only" ) do @amendable.assign_attributes(form.emendation_params) - @amendable.title = { I18n.locale => form.emendation_params.with_indifferent_access[:title] } - @amendable.body = { I18n.locale => form.emendation_params.with_indifferent_access[:body] } + if @amendable.official? + # official proposals can be translated, when amending them, we want to keep the translations + # (admins will have to update it afterwards if needed) so we assign the original attributes first + @amendable.title = @emendation.amendable.title + @amendable.title[I18n.locale.to_s] = form.emendation_params.with_indifferent_access[:title] + @amendable.body = @emendation.amendable.body + @amendable.body[I18n.locale.to_s] = form.emendation_params.with_indifferent_access[:body] + else + # For non-official proposals, we only allow one locale, so we just assign the new values. + # Note that this will trigger the automatic translation if enabled + # effectively changing the original language in what the proposal was writen + @amendable.title = { I18n.locale => form.emendation_params.with_indifferent_access[:title] } + @amendable.body = { I18n.locale => form.emendation_params.with_indifferent_access[:body] } + end @amendable.save! @amendable end diff --git a/decidim-core/app/controllers/concerns/decidim/amendments_controller.rb b/decidim-core/app/controllers/concerns/decidim/amendments_controller.rb index 08f8a6fd5cb72..cfae37e3fc2d6 100644 --- a/decidim-core/app/controllers/concerns/decidim/amendments_controller.rb +++ b/decidim-core/app/controllers/concerns/decidim/amendments_controller.rb @@ -11,6 +11,8 @@ class AmendmentsController < Decidim::ApplicationController helper_method :amendment, :amendable, :emendation, :similar_emendations before_action :ensure_is_draft_from_user, only: [:compare_draft, :edit_draft, :update_draft, :destroy_draft, :preview_draft, :publish_draft] + around_action :ensure_locale_on_review, only: [:review] + def new raise ActionController::RoutingError, "Not Found" unless amendable @@ -192,6 +194,16 @@ def withdraw private + def ensure_locale_on_review + emendation_locale = (emendation.title.keys - ["machine_translations"]).first + if current_locale.to_s != emendation_locale + flash[:alert] = t("locale_changed", scope: "decidim.amendments.review", lang: t("locale.name", locale: emendation_locale)) + end + I18n.with_locale(emendation_locale) do + yield + end + end + # GlobalID::SignedGlobalID parameter to locate the amendable resource. # Needed for actions :new and :create, when there is no amendment yet. def amendable_gid diff --git a/decidim-core/config/locales/en.yml b/decidim-core/config/locales/en.yml index d000b613685fe..605b2a0009e08 100644 --- a/decidim-core/config/locales/en.yml +++ b/decidim-core/config/locales/en.yml @@ -322,6 +322,7 @@ en: back: Back heading: Review the amendment help_text: You are reviewing an amendment to the %{model_name} + locale_changed: This amendment is being made for the "%{lang}" language. The display language has been changed to prevent misunderstandings. send: Accept amendment update_draft: error: There was a problem updating the amendment draft.