|
14 | 14 | from pontoon.base.models.translation import TranslationQuerySet |
15 | 15 | from pontoon.base.user_utils import get_pretranslation_authors |
16 | 16 | from pontoon.batch import utils |
| 17 | +from pontoon.checks.libraries import run_checks |
| 18 | +from pontoon.checks.utils import bulk_run_checks |
17 | 19 | from pontoon.messaging.notifications import send_badge_notification |
18 | 20 | from pontoon.pretranslation.pretranslate import get_pretranslation |
19 | 21 | from pontoon.translations.utils import parse_source_string_to_json |
@@ -445,6 +447,20 @@ def pretranslate_translations(user, locale: Locale, entities: QuerySet[Entity]): |
445 | 447 | invalid_entity_pks.append(entity.pk) |
446 | 448 | continue |
447 | 449 |
|
| 450 | + failed_checks = run_checks( |
| 451 | + entity, locale.code, pretranslation[0], use_tt_checks=False |
| 452 | + ) |
| 453 | + |
| 454 | + if failed_checks: |
| 455 | + try: |
| 456 | + pretranslation = get_pretranslation( |
| 457 | + entity, locale, preserve_placeables=True |
| 458 | + ) |
| 459 | + except ValueError as e: |
| 460 | + logger.info(f"Pretranslation error for entity {entity.pk}: {e!r}") |
| 461 | + invalid_entity_pks.append(entity.pk) |
| 462 | + continue |
| 463 | + |
448 | 464 | string, author_key = pretranslation |
449 | 465 |
|
450 | 466 | try: |
@@ -475,9 +491,11 @@ def pretranslate_translations(user, locale: Locale, entities: QuerySet[Entity]): |
475 | 491 | ) |
476 | 492 |
|
477 | 493 | changed_translations = Translation.objects.bulk_create(translations_to_create) |
478 | | - changed_translations_qs = Translation.objects.filter( |
479 | | - pk__in=[t.pk for t in changed_translations] |
480 | | - ) |
| 494 | + |
| 495 | + translation_pks = {t.pk for t in changed_translations} |
| 496 | + bulk_run_checks(Translation.objects.for_checks().filter(pk__in=translation_pks)) |
| 497 | + |
| 498 | + changed_translations_qs = Translation.objects.filter(pk__in=translation_pks) |
481 | 499 |
|
482 | 500 | count, translated_resources, changed_entities = utils.get_translations_info( |
483 | 501 | changed_translations_qs, locale |
@@ -505,6 +523,7 @@ def pretranslate_translations(user, locale: Locale, entities: QuerySet[Entity]): |
505 | 523 | else None, |
506 | 524 | "changed_translation_pks": changed_translation_pks, |
507 | 525 | "invalid_translation_pks": invalid_entity_pks, |
| 526 | + "badge_update": {}, |
508 | 527 | } |
509 | 528 |
|
510 | 529 |
|
|
0 commit comments