Repository: mozilla/pontoon

Issue:
Don't submit pretranslated strings with warnings or errors
If possible, it would be great to have 2 different behaviors:
* Strings with warning should be suggested, instead of submitted, because they might be OK (i.e. the warning could be ignored), or at least it might be still useful to post-edit them instead of starting from scratch.
* String with errors shouldn't be even suggested.

If not possible, I guess storing them both as suggestions would work, since the localizer wouldn't be able to confirm a string with errors (but it will be confusing).

The important piece is not storing them in VCS, because it will create a chain of errors, especially in parts that we don't control (the final product).


Discussion:
I have another case (caused by #2690)

<img width="1043" alt="Schermata 2023-01-19 alle 21 16 19" src="https://user-images.githubusercontent.com/3644868/213550951-61270929-f2f9-4181-a12a-de0765993828.png">



With #2690, #2733, #2734 and the likes fixed, the number of Errors and Warnings will go down significantly.

I suggest we focus on Errors in this issue and do as suggested - not store them.

For Warnings, I'd wait until Fluent Pretranslation improvement issues are fixed and then see what to do - either do as suggested here or keep the current behavior. I'd track that in a separate (P3) issue.
I think we need to bump priority.

14 errors generated for zh-TW.
https://pontoon.mozilla.org/zh-TW/mozillaorg/all-resources/?time=202304021244-202304021344&string=215305

What's worse, is that I've rejected them in Pontoon, but it didn't remove them from the repository (filing a separate issue to investigate that).
Android projects are another source of errors, because of unescaped quotes (we have 2 for Welsh)

Resolving patch:
diff --git a/pontoon/pretranslation/tasks.py b/pontoon/pretranslation/tasks.py
--- a/pontoon/pretranslation/tasks.py
+++ b/pontoon/pretranslation/tasks.py
@@ -171,7 +171,12 @@ def pretranslate(self, project_pk, locales=None, entities=None):
     bulk_run_checks(Translation.objects.for_checks().filter(pk__in=translation_pks))
 
     # Mark translations as changed
-    changed_translations = Translation.objects.filter(pk__in=translation_pks)
+    changed_translations = Translation.objects.filter(
+        pk__in=translation_pks,
+        # Do not sync translations with errors and warnings
+        errors__isnull=True,
+        warnings__isnull=True,
+    )
     changed_translations.bulk_mark_changed()
 
     # Update latest activity and stats for changed instances.


Test patch:
diff --git a/pontoon/pretranslation/tests/test_tasks.py b/pontoon/pretranslation/tests/test_tasks.py
--- a/pontoon/pretranslation/tests/test_tasks.py
+++ b/pontoon/pretranslation/tests/test_tasks.py
@@ -2,7 +2,7 @@
 
 import pytest
 
-from pontoon.base.models import User, Translation
+from pontoon.base.models import ChangedEntityLocale, Translation, User
 from pontoon.pretranslation.tasks import pretranslate
 from pontoon.test.factories import (
     EntityFactory,
@@ -44,16 +44,18 @@ def test_pretranslate(gt_mock, project_a, locale_a, resource_a, locale_b):
         pretranslation_enabled=True,
     )
 
-    tm_user = User.objects.get(email="pontoon-tm@example.com")
-    gt_mock.return_value = [("pretranslation", None, tm_user)]
+    gt_user = User.objects.get(email="pontoon-gt@example.com")
+    gt_mock.return_value = [("pretranslation", None, gt_user)]
 
     pretranslate(project_a.pk)
     project_a.refresh_from_db()
-    translations = Translation.objects.filter(user=tm_user)
+    translations = Translation.objects.filter(user=gt_user)
 
     # Total pretranslations = 2(tr_ax) + 2(tr_bx) + 2(tr_ay)
     assert len(translations) == 6
 
+    assert ChangedEntityLocale.objects.all().count() == 6
+
     # pretranslated count == total pretranslations.
     assert project_a.pretranslated_strings == 6