wagtail / wagtail-localize

Translation plugin for Wagtail CMS
https://wagtail-localize.org/
Other
222 stars 84 forks source link

Let machine translators skip fields #819

Open tognee opened 2 weeks ago

tognee commented 2 weeks ago

Currently there is no way to keep a field not translated in case of issues with the machine translator. Setting the value to an empty StringValue will show the field as translated in the admin.

This patch will let machine translators omit the key value pair to keep the field not translated.

(Sorry for the double PR, had issues with my linter)

codecov-commenter commented 2 weeks ago

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.02%. Comparing base (f465821) to head (5aa3c86).

Files with missing lines Patch % Lines
wagtail_localize/views/edit_translation.py 0.00% 1 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #819 +/- ## ========================================== - Coverage 93.07% 93.02% -0.05% ========================================== Files 47 47 Lines 4144 4146 +2 Branches 704 705 +1 ========================================== Hits 3857 3857 - Misses 173 174 +1 - Partials 114 115 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

zerolab commented 1 week ago

Any chance you could add a test or two?

tognee commented 1 week ago

To add tests I would need to add a machine translator that could fail. Can I edit the dummy translator so that it doesn't generate a response if the text to translate is more than 50 words, or should I add another machine translator just for the test?

zerolab commented 1 week ago

You could mock patch https://github.com/wagtail/wagtail-localize/blob/main/wagtail_localize/machine_translators/dummy.py#L23 for your test only

tognee commented 1 week ago

For my first implementation I would need to patch the translate method in the DummyTranslator class. I've extended the implementation to check if the StringValue data is null.

Added tests for both of them and it seems to be working.