Skip to content

Commit

Permalink
When approving matching prior translations, do not also reject them
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Dec 18, 2024
1 parent 357f7fe commit 008fa56
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion pontoon/sync/core/translations_from_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,15 @@ def update_db_translations(
actions.append(
ActionLog(
action_type=ActionLog.ActionType.TRANSLATION_APPROVED,
created_at=now,
performed_by=log_user,
translation=tx,
)
)
approve_count += 1
translations_to_reject |= Q(
entity=tx.entity, locale=tx.locale, plural_form=tx.plural_form
)
) & ~Q(id=tx.id)
update_fields.update(tx.get_dirty_fields())
for entity_id, locale_id, _ in suggestions:
try:
Expand Down Expand Up @@ -384,6 +385,7 @@ def update_db_translations(
actions.extend(
ActionLog(
action_type=ActionLog.ActionType.TRANSLATION_REJECTED,
created_at=now,
performed_by=log_user,
translation=tx,
is_implicit_action=True,
Expand Down
36 changes: 31 additions & 5 deletions pontoon/sync/tests/test_translations_from_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from django.conf import settings
from django.utils import timezone

from pontoon.base.models import TranslatedResource, Translation, TranslationMemoryEntry
from pontoon.actionlog.models import ActionLog
from pontoon.base.models import (
Entity,
TranslatedResource,
Translation,
TranslationMemoryEntry,
)
from pontoon.base.tests import (
EntityFactory,
LocaleFactory,
Expand Down Expand Up @@ -63,6 +69,11 @@ def test_add_ftl_translation():
active=True,
approved=True,
)
TranslationFactory.create(
entity=Entity.objects.get(resource=res["c"], key="key-c-1"),
locale=locale,
string="key-c-1 = New translation c 1\n",
)

project.refresh_from_db()
assert project.total_strings == 9
Expand All @@ -72,8 +83,8 @@ def test_add_ftl_translation():
c_ftl = dedent(
"""
key-c-0 = Translation c 0
key-c-1 = Translation c 1
key-c-2 = Translation c 2
key-c-1 = New translation c 1
key-c-2 = New translation c 2
"""
)
makedirs(repo.checkout_path)
Expand Down Expand Up @@ -108,15 +119,30 @@ def test_add_ftl_translation():
tr_c2 = next(trans for trans in translations if trans.entity.key == "key-c-2")
assert not tr_c2.user

# Test actions
assert {
(action.translation.string, action.action_type)
for action in ActionLog.objects.filter(translation__in=translations)
} == {
("key-c-1 = Translation c 1\n", "translation:rejected"),
("key-c-1 = New translation c 1\n", "translation:approved"),
("key-c-2 = New translation c 2\n", "translation:created"),
}

# Test stats
update_stats(project)
project.refresh_from_db()
assert project.total_strings == 9
assert project.approved_strings == 9
tm = TranslationMemoryEntry.objects.filter(
entity__resource=res["c"], translation__isnull=False
)
assert len(tm) == 3
).values_list("target", flat=True)
assert set(tm) == {
"Translation c 0",
"Translation c 1",
"New translation c 1",
"New translation c 2",
}


@pytest.mark.django_db
Expand Down

0 comments on commit 008fa56

Please sign in to comment.