Skip to content

Commit

Permalink
Count translation updates before dropping approvals from the dict
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Dec 18, 2024
1 parent ff95768 commit c931f71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pontoon/sync/core/translations_from_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def sync_translations_from_repo(
db_changes: BaseManager[ChangedEntityLocale],
now: datetime,
) -> tuple[int, int]:
"""(removed_count, updated_count)"""
"""(removed_resource_count, updated_translation_count)"""
co = checkouts.target
source_paths: set[str] = set(paths.ref_paths) if checkouts.source == co else set()
del_count = delete_removed_bilingual_resources(project, co, paths, source_paths)
Expand All @@ -67,9 +67,10 @@ def sync_translations_from_repo(
updates = find_db_updates(
project, locale_map, changed_target_paths, paths, db_changes
)
update_count = 0 if updates is None else len(updates)
if updates:
write_db_updates(project, updates, None, now)
return del_count, 0 if updates is None else len(updates)
return del_count, update_count


def write_db_updates(
Expand Down
10 changes: 8 additions & 2 deletions pontoon/sync/tests/test_translations_from_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def test_add_ftl_translation():
paths = find_paths(project, checkouts)

# Test sync
sync_translations_from_repo(project, locale_map, checkouts, paths, [], now)
removed_resources, updated_translations = sync_translations_from_repo(
project, locale_map, checkouts, paths, [], now
)
assert (removed_resources, updated_translations) == (0, 2)
translations = Translation.objects.filter(
entity__resource=res["c"], locale=locale
)
Expand Down Expand Up @@ -195,7 +198,10 @@ def test_remove_po_target_resource():
paths = find_paths(project, checkouts)

# Test sync
sync_translations_from_repo(project, locale_map, checkouts, paths, [], now)
removed_resources, updated_translations = sync_translations_from_repo(
project, locale_map, checkouts, paths, [], now
)
assert (removed_resources, updated_translations) == (1, 0)
assert not TranslatedResource.objects.filter(locale=locale, resource=res["b"])
assert not Translation.objects.filter(entity__resource=res["b"], locale=locale)
tm = TranslationMemoryEntry.objects.filter(
Expand Down

0 comments on commit c931f71

Please sign in to comment.