Skip to content

Remove aliases instead of failing #54

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 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions manage_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from contextlib import chdir
from dataclasses import dataclass
from difflib import SequenceMatcher
from itertools import combinations
from pathlib import Path
from subprocess import call
import sys
Expand Down Expand Up @@ -154,7 +153,7 @@ def progress_from_resources(resources: Iterable[ResourceLanguageStatistics]) ->
def get_number_of_translators():
translators = set(_fetch_translators())
_remove_bot(translators)
_check_for_aliases(translators)
translators = _eliminate_aliases(translators)
return len(translators)


Expand All @@ -170,12 +169,18 @@ def _remove_bot(translators: set[str]) -> None:
translators.remove("Transifex Bot <>")


def _check_for_aliases(translators) -> None:
for pair in combinations(translators, 2):
if (ratio := SequenceMatcher(lambda x: x in '<>@', *pair).ratio()) > 0.64:
warn(
f"{pair} are similar ({ratio:.3f}). Please add them to aliases list or bump the limit."
)
def _eliminate_aliases(translators: set[str]) -> set[str]:
unique = set()
for name in translators:
for match in unique:
if (ratio := SequenceMatcher(lambda x: x in '<>@', name, match).ratio()) > 0.64:
print(
f"{pair} are similar ({ratio:.3f}). Deduplicating."
)
break
else:
unique.add(name)
return unique


def language_switcher(entry: ResourceLanguageStatistics) -> bool:
Expand Down
Loading