Skip to content

Commit

Permalink
Don't run translations if not set (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandfardeau authored Aug 16, 2023
1 parent 94d1f81 commit df4c8ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/tasks/repair_data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ namespace :decidim do
desc "Add all missing translation for translatable resources"
task translations: :environment do
logger = Logger.new($stdout)
logger.info("Checking all translatable resources...")
if Decidim.enable_machine_translations
logger.info("Checking all translatable resources...")

updated_resources_ids = Decidim::RepairTranslationsService.run(logger: logger)
updated_resources_ids = Decidim::RepairTranslationsService.run(logger: logger)

if updated_resources_ids.blank?
logger.info("No resources updated")
if updated_resources_ids.blank?
logger.info("No resources updated")
else
logger.info("#{updated_resources_ids.count} resources enqueue for translation")
logger.info("Enqueued resources : #{updated_resources_ids.join(", ")}")
end

logger.info("Operation terminated")
else
logger.info("#{updated_resources_ids.count} resources enqueue for translation")
logger.info("Enqueued resources : #{updated_resources_ids.join(", ")}")
logger.warn("Machine translation is not enabled")
end

logger.info("Operation terminated")
end

task url_in_content: :environment do
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/tasks/repair_data_translations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
describe "rake decidim:repair:translations", type: :task do
let(:task) { Rake::Task[:"decidim:repair:translations"] }
let!(:comment) { create(:comment) }
let(:enable_machine_translations) { true }

before do
clear_enqueued_jobs
clear_performed_jobs
allow(Decidim).to receive(:enable_machine_translations).and_return(enable_machine_translations)
end

after do
Expand All @@ -25,4 +27,14 @@

task.execute
end

context "when translation is not activated" do
let(:enable_machine_translations) { false }

it "doesn't calls the service" do
expect(Decidim::RepairTranslationsService).not_to receive(:run)

task.execute
end
end
end

0 comments on commit df4c8ce

Please sign in to comment.