Skip to content

Commit 008fa56

Browse files
committed
When approving matching prior translations, do not also reject them
1 parent 357f7fe commit 008fa56

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

pontoon/sync/core/translations_from_repo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,15 @@ def update_db_translations(
329329
actions.append(
330330
ActionLog(
331331
action_type=ActionLog.ActionType.TRANSLATION_APPROVED,
332+
created_at=now,
332333
performed_by=log_user,
333334
translation=tx,
334335
)
335336
)
336337
approve_count += 1
337338
translations_to_reject |= Q(
338339
entity=tx.entity, locale=tx.locale, plural_form=tx.plural_form
339-
)
340+
) & ~Q(id=tx.id)
340341
update_fields.update(tx.get_dirty_fields())
341342
for entity_id, locale_id, _ in suggestions:
342343
try:
@@ -384,6 +385,7 @@ def update_db_translations(
384385
actions.extend(
385386
ActionLog(
386387
action_type=ActionLog.ActionType.TRANSLATION_REJECTED,
388+
created_at=now,
387389
performed_by=log_user,
388390
translation=tx,
389391
is_implicit_action=True,

pontoon/sync/tests/test_translations_from_repo.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
from django.conf import settings
1010
from django.utils import timezone
1111

12-
from pontoon.base.models import TranslatedResource, Translation, TranslationMemoryEntry
12+
from pontoon.actionlog.models import ActionLog
13+
from pontoon.base.models import (
14+
Entity,
15+
TranslatedResource,
16+
Translation,
17+
TranslationMemoryEntry,
18+
)
1319
from pontoon.base.tests import (
1420
EntityFactory,
1521
LocaleFactory,
@@ -63,6 +69,11 @@ def test_add_ftl_translation():
6369
active=True,
6470
approved=True,
6571
)
72+
TranslationFactory.create(
73+
entity=Entity.objects.get(resource=res["c"], key="key-c-1"),
74+
locale=locale,
75+
string="key-c-1 = New translation c 1\n",
76+
)
6677

6778
project.refresh_from_db()
6879
assert project.total_strings == 9
@@ -72,8 +83,8 @@ def test_add_ftl_translation():
7283
c_ftl = dedent(
7384
"""
7485
key-c-0 = Translation c 0
75-
key-c-1 = Translation c 1
76-
key-c-2 = Translation c 2
86+
key-c-1 = New translation c 1
87+
key-c-2 = New translation c 2
7788
"""
7889
)
7990
makedirs(repo.checkout_path)
@@ -108,15 +119,30 @@ def test_add_ftl_translation():
108119
tr_c2 = next(trans for trans in translations if trans.entity.key == "key-c-2")
109120
assert not tr_c2.user
110121

122+
# Test actions
123+
assert {
124+
(action.translation.string, action.action_type)
125+
for action in ActionLog.objects.filter(translation__in=translations)
126+
} == {
127+
("key-c-1 = Translation c 1\n", "translation:rejected"),
128+
("key-c-1 = New translation c 1\n", "translation:approved"),
129+
("key-c-2 = New translation c 2\n", "translation:created"),
130+
}
131+
111132
# Test stats
112133
update_stats(project)
113134
project.refresh_from_db()
114135
assert project.total_strings == 9
115136
assert project.approved_strings == 9
116137
tm = TranslationMemoryEntry.objects.filter(
117138
entity__resource=res["c"], translation__isnull=False
118-
)
119-
assert len(tm) == 3
139+
).values_list("target", flat=True)
140+
assert set(tm) == {
141+
"Translation c 0",
142+
"Translation c 1",
143+
"New translation c 1",
144+
"New translation c 2",
145+
}
120146

121147

122148
@pytest.mark.django_db

0 commit comments

Comments
 (0)