Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store pretranslations for each locale separately #3075

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 37 additions & 34 deletions pontoon/pretranslation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ def pretranslate(self, project_pk, locales=None, entities=None):

translated_entities = list(translated_entities)

translations = []
for locale in locales:
log.info(f"Fetching pretranslations for locale {locale.code} started")

# To keep track of changed TranslatedResources and their latest_translation
tr_dict = {}
translations = []

tr_filter = []
index = -1
# To keep track of changed TranslatedResources and their latest_translation
tr_dict = {}
tr_filter = []
index = -1

for locale in locales:
log.info(f"Fetching pretranslations for locale {locale.code} started")
for entity in entities:
locale_entity = f"{locale.id}-{entity.id}"
locale_resource = f"{locale.id}-{entity.resource.id}"
Expand Down Expand Up @@ -165,39 +165,42 @@ def pretranslate(self, project_pk, locales=None, entities=None):
# Update the latest translation index
tr_dict[locale_resource] = index

log.info(f"Fetching pretranslations for locale {locale.code} done")
if len(translations) == 0:
log.info(
f"Fetching pretranslations for locale {locale.code} done: No pretranslation fetched"
)
continue

if len(translations) == 0:
return
translations = Translation.objects.bulk_create(translations)

translations = Translation.objects.bulk_create(translations)
# Log creating actions
actions_to_log = [
ActionLog(
action_type=ActionLog.ActionType.TRANSLATION_CREATED,
performed_by=t.user,
translation=t,
)
for t in translations
]

# Log creating actions
actions_to_log = [
ActionLog(
action_type=ActionLog.ActionType.TRANSLATION_CREATED,
performed_by=t.user,
translation=t,
)
for t in translations
]
ActionLog.objects.bulk_create(actions_to_log)

ActionLog.objects.bulk_create(actions_to_log)
# Run checks on all translations
translation_pks = {translation.pk for translation in translations}
bulk_run_checks(Translation.objects.for_checks().filter(pk__in=translation_pks))

# Run checks on all translations
translation_pks = {translation.pk for translation in translations}
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,
# Do not sync translations with errors and warnings
errors__isnull=True,
warnings__isnull=True,
)
changed_translations.bulk_mark_changed()

# Mark translations as changed
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.
update_changed_instances(tr_filter, tr_dict, translations)

# Update latest activity and stats for changed instances.
update_changed_instances(tr_filter, tr_dict, translations)
log.info(f"Fetching pretranslations for locale {locale.code} done")

log.info(f"Fetching pretranslations for project {project.name} done")
Loading