Skip to content

Conversation

BarbaraOliveira13
Copy link
Contributor

@BarbaraOliveira13 BarbaraOliveira13 commented Sep 8, 2025

🎩 Description

Previously, we manually configured all DeepL integration details in our fork.
Now, that the base machine translation framework is integrated upstream in decidim/decidim,
This PR configures DeepL as the machine translation service using the new Decidim configuration system.

✅ Testing

SET UP

  1. Set your Deeple API key in your environment => for exemple when you run your server, you can use this command: DEEPL_API_KEY="ta_clef_ici" bin/rails server
  2. Run sidekiq, in a new tab => bundle exec sidekiq -q translations
  3. Log as admin and go to the dashboard
  4. Navigate to Settings → Configuration
  5. Check 'enable machine translation'
config_machine_tranlation You now can see this warning : Capture d’écran 2025-09-10 à 15 57 00 ___________

TEST

  1. Create or Edit a translable content as 'proposal' or 'comment' in fr for exemple
  2. Change the interface language
Capture d’écran 2025-09-12 à 11 48 32 3. You should see an automatic translation 🎉 Capture d’écran 2025-09-12 à 11 48 52

📌 Related Issues

[Link your PR to an issue

Tasks

  • Add specs
  • Add note about overrides in OVERLOADS.md
  • In case of new dependencies or version bump, update related documentation

📷 Screenshots

Please add screenshots of the changes you're proposing if related to the UI

Extra information

@BarbaraOliveira13 BarbaraOliveira13 force-pushed the fix/machine-translation-clean branch from 62ad22b to 3378ee6 Compare September 19, 2025 07:28
@BarbaraOliveira13 BarbaraOliveira13 marked this pull request as draft September 19, 2025 07:29
Comment on lines 19 to 26
translation = ::DeepL.translate text, source_locale.to_s, target_locale.to_s

Decidim::MachineTranslationSaveJob.perform_later(
resource,
field_name,
target_locale,
translation.text
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might consider adding a guard clause after the DeepL API call to prevent scheduling a job with empty/nil translation results:

translation = ::DeepL.translate text, source_locale.to_s, target_locale.to_s
return nil if translation.nil? || translation.text.blank?

Decidim::MachineTranslationSaveJob.perform_later(...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great to include tests ! Personally, I think we're missing some test coverage here, especially around error scenarios. Since this class makes external API calls, it would be good to test what happens when:

  • The translation comes back nil or empty
  • We pass blank text

That would be a bonus (so if you can't do it, it's fine) to add some tests about:

  • The job scheduling fails
  • The DeepL API fails (auth errors, quota exceeded, etc.)

The current test only covers the happy path integration, which is great, but given the previous feedback about error handling, it would probably be worth adding some unit tests for the #translate method to make sure errors are logged properly and don't break the flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback It's great, I will add them !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had them. About The job scheduling I think is almost test in the machine_translation_resource_job: https://github.com/decidim/decidim/blob/7d584a3cd73c93d8eb3bcdf8c0eb8e1b3562d9bf/decidim-core/spec/jobs/decidim/machine_translation_resource_job_spec.rb#L23
Do you think is still necessary here ? I'm not sure...

@BarbaraOliveira13 BarbaraOliveira13 marked this pull request as ready for review September 22, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants