From 70a59fb3d9586c2a428d20522d7e1c2db6132b79 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 21 Nov 2024 16:14:21 +0100 Subject: [PATCH] Rake task to update budget proposals translations (#576) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fran Bolívar --- README.md | 12 +++++ .../proposals_budget_2024_translations.rake | 54 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 lib/tasks/proposals_budget_2024_translations.rake diff --git a/README.md b/README.md index f8839e839..4f7a5e2ce 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,18 @@ For example, this one will remove all the notifications from 2023-11-12 to 2024- bundle exec rake notifications:destroy_old["2024-01-01","2023-11-12"] ``` +### Update 2024 Participatory budget proposals to fix missing translations + +The proposals inside the 2024 participatory budget, sometimes, are created without the translations of the `copy_id` generated using the Term Customizer module. + +This rake task will update the content of the proposals that have not translated the content and save them with the correct translation. + +You can call this tasks for the two languages being used in the participatory process (Catalan and Spanish): + +```bash +bundle exec rake proposals_budget_2024_translations:update_ca_translations +``` + ## License Code published under AFFERO GPL v3 (see [LICENSE-AGPLv3.txt](LICENSE-AGPLv3.txt)) diff --git a/lib/tasks/proposals_budget_2024_translations.rake b/lib/tasks/proposals_budget_2024_translations.rake new file mode 100644 index 000000000..61051d6e8 --- /dev/null +++ b/lib/tasks/proposals_budget_2024_translations.rake @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +namespace :proposals_budget_2024_translations do + desc "[CATALAN] Fix translations in proposals for the 2024 particiatory budget" + task update_ca_translations: :environment do + updated_content = { + "decidim.barcelona.pressupostos.2024.pregunta2.enunciat" => "Estat actual i problemes a resoldre:", + "decidim.barcelona.pressupostos.2024.pregunta3.enunciat" => "Descripció de la proposta i impacte esperat:", + "decidim.barcelona.pressupostos.2024.pregunta4.enunciat" => "Cost aproximat (opcional):", + "decidim.barcelona.pressupostos.2024.pregunta5.enunciat" => "A qui més pot interessar la proposta i estaria bé tenir en compte en el projecte?" + } + + update_content_for_lang "ca", updated_content + end + + desc "[SPANISH] Fix translations in proposals for the 2024 particiatory budget" + task update_es_translations: :environment do + updated_content = { + "decidim.barcelona.pressupostos.2024.pregunta2.enunciat" => "Estado actual y problemas a resolver:", + "decidim.barcelona.pressupostos.2024.pregunta3.enunciat" => "Descripción de la propuesta e impacto esperado:", + "decidim.barcelona.pressupostos.2024.pregunta4.enunciat" => "Coste aproximado (opcional):", + "decidim.barcelona.pressupostos.2024.pregunta5.enunciat" => "¿A quién más puede interesarle la propuesta y estaría bien tener en cuenta en el proyecto?" + } + + update_content_for_lang "es", updated_content + end + + def update_content_for_lang(lang, content) + puts "Processing lang #{lang}" + + proposals = Decidim::Proposals::Proposal.where( + "body ->> '#{lang}' LIKE ?", "%decidim.barcelona.pressupostos.2024.pregunta2.enunciat%" + ) + + puts "There are #{proposals.count} proposals to update" + + proposals.find_each do |proposal| + puts "Processing Proposal ID: #{proposal.id}" + + body = proposal.body[lang] + + content.each do |copy_id, new_text| + puts "Updating #{copy_id} for Proposal ID: #{proposal.id}" + + body[copy_id] = new_text + end + + proposal.body[lang] = body + proposal.save! + + puts "Successfully updated #{lang} content for Proposal ID: #{proposal.id}" + end + end +end