Skip to content

Commit 93255ed

Browse files
authored
Remove aliases instead of failing (#54)
1 parent dd46e54 commit 93255ed

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

manage_translation.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from contextlib import chdir
1818
from dataclasses import dataclass
1919
from difflib import SequenceMatcher
20-
from itertools import combinations
2120
from pathlib import Path
2221
from subprocess import call
2322
import sys
@@ -154,7 +153,7 @@ def progress_from_resources(resources: Iterable[ResourceLanguageStatistics]) ->
154153
def get_number_of_translators():
155154
translators = set(_fetch_translators())
156155
_remove_bot(translators)
157-
_check_for_aliases(translators)
156+
translators = _eliminate_aliases(translators)
158157
return len(translators)
159158

160159

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

172171

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

180185

181186
def language_switcher(entry: ResourceLanguageStatistics) -> bool:

0 commit comments

Comments
 (0)