Skip to content

Commit

Permalink
Merge branch 'versioning' into segment-context-base
Browse files Browse the repository at this point in the history
  • Loading branch information
kaedroho committed Jan 2, 2020
2 parents f0968fc + 983ae3f commit ef567a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion wagtail_localize/translation_engines/pontoon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ class PontoonResourceTranslation(models.Model):

@transaction.atomic
def submit_to_pontoon(instance):
revision = TranslatableRevision.from_instance(instance)
revision, created = TranslatableRevision.from_instance(instance)

if not created:
# Check if there is already a submission for this revision
if PontoonResourceSubmission.objects.filter(revision=revision).exists():
return

# Extract segments from revision and save them to translation memory
segments = extract_segments(instance)
Expand Down Expand Up @@ -369,6 +374,11 @@ def submit_page_to_pontoon(page_revision):
page_revision
)

if not created:
# Check if there is already a submission for this revision
if PontoonResourceSubmission.objects.filter(revision=revision).exists():
return

# Extract segments from revision and save them into translation memory
segments = extract_segments(page_revision.as_page_object())
insert_segments(revision, revision.locale.language_id, segments)
Expand Down
4 changes: 2 additions & 2 deletions wagtail_localize/translation_memory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ def from_instance(cls, instance, force=False):
previous_revision = object.revisions.order_by("created_at").last()
if previous_revision:
if content_json == previous_revision.content_json:
return previous_revision
return previous_revision, False

return cls.objects.create(
object=object,
locale=instance.locale,
content_json=content_json,
created_at=timezone.now(),
)
), True

def as_instance(self):
"""
Expand Down

0 comments on commit ef567a8

Please sign in to comment.