Repository navigation
Batch actions: Add the ability to pretranslate strings #4455
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b85e30a
Fixes #2790
MundiaNderi c09df38
Restrict pretranslation to the pretranslators group
MundiaNderi 0a50f41
Batch pretranslation now skips entities whose translation-memory/MT
MundiaNderi 7b7ed3b
Remove dead pretranslation-in-progress banner from EditorMenu
MundiaNderi 2e15722
Keep track of invalid pretranslations skipped due to a missing
MundiaNderi 75bc582
Pretranslate: skip existing pretranslations, include fuzzy, attribute…
MundiaNderi 4d46b55
Pretranslate: run checks and retry with preserved placeables
MundiaNderi c35ec9e
Show in-progress state while batch pretranslation runs
MundiaNderi 765bb42
Pretranslate: make activation race-safe, report translations with err…
MundiaNderi 03e9631
Fix batch pretranslation stats, error counts and polling
MundiaNderi dfe05c5
Address review: pass SYNC_TASK_TIMEOUT to client, log activation fail…
MundiaNderi 43f7a85
Updating batch actions documentation
MundiaNderi 8041f13
Updating documentation
MundiaNderi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
-9.58 KB
(97%)
documentation/docs/assets/localizer/translate/batch_actions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import logging | ||
|
|
||
| from celery import shared_task | ||
|
|
||
| from django.core.cache import cache | ||
|
|
||
| from pontoon.base.models import Entity, Locale, TranslatedResource, Translation, User | ||
| from pontoon.base.tasks import PontoonTask | ||
| from pontoon.batch.actions import pretranslate_translations | ||
|
|
||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @shared_task(base=PontoonTask, name="batch_pretranslate") | ||
| def batch_pretranslate_task(user_pk, locale_pk, entity_pks): | ||
| lock_name = f"batch_pretranslate_{locale_pk}" | ||
| try: | ||
| user = User.objects.get(pk=user_pk) | ||
| locale = Locale.objects.get(pk=locale_pk) | ||
| entities = Entity.objects.filter(pk__in=entity_pks) | ||
| action_status = pretranslate_translations(user, locale, entities) | ||
|
|
||
| tr_pks = [tr.pk for tr in action_status["translated_resources"]] | ||
| TranslatedResource.objects.filter(pk__in=tr_pks).calculate_stats() | ||
|
|
||
| if action_status["count"] > 0: | ||
| Translation.objects.filter( | ||
| pk__in=action_status["changed_translation_pks"] | ||
| ).bulk_mark_changed() | ||
|
|
||
| changed_entity_pks = [e.pk for e in action_status["changed_entities"]] | ||
| for e in Entity.objects.filter( | ||
| pk__in=changed_entity_pks, | ||
| resource__project__slug="terminology", | ||
| ): | ||
| e.reset_term_translation(locale) | ||
|
|
||
| if action_status["latest_translation_pk"]: | ||
| Translation.objects.get( | ||
| pk=action_status["latest_translation_pk"] | ||
| ).update_latest_translation() | ||
|
|
||
| cache.set( | ||
| f"{lock_name}_result", | ||
| { | ||
| "count": action_status["count"], | ||
| "invalid_translation_count": len( | ||
| action_status.get("invalid_translation_pks", []) | ||
| ) | ||
| + len(action_status.get("invalid_entity_pks", [])), | ||
| }, | ||
| timeout=3600, | ||
| ) | ||
| except Exception: | ||
| log.exception("Batch pretranslation failed") | ||
| cache.set(f"{lock_name}_result", {"error": True}, timeout=3600) | ||
| raise | ||
| finally: | ||
| cache.delete(lock_name) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.