Skip to content

Commit cb61f5c

Browse files
committed
"fuzzy" detection extend and marking "must"-translation files.
1 parent 946f944 commit cb61f5c

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

po_status.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
r"(?:, (\d+) fuzzy translations?)?"
1515
r"(?:, (\d+) untranslated messages?)?"
1616
)
17+
CORE_FILES = {"bugs.po", "builtins/functions.po"}
18+
CORE_DIRS = ("tutorial/",)
19+
FUZZY_FLAG_RE = re.compile(r"^#,.*\bfuzzy\b", re.MULTILINE)
1720

1821

1922
def get_stats(po_file: Path):
@@ -38,6 +41,18 @@ def get_stats(po_file: Path):
3841
return {"translated": translated, "fuzzy": fuzzy, "untranslated": untranslated}
3942

4043

44+
def count_fuzzy_flags(po_file: Path) -> int:
45+
"""Zählt alle fuzzy-Markierungen direkt im Dateitext."""
46+
text = po_file.read_text(encoding="utf-8", errors="replace")
47+
return len(FUZZY_FLAG_RE.findall(text))
48+
49+
50+
def is_core(rel_path: Path) -> bool:
51+
"""Prüft, ob die Datei zu den Pflichtartikeln gehört."""
52+
rel = rel_path.as_posix()
53+
return rel in CORE_FILES or rel.startswith(CORE_DIRS)
54+
55+
4156
def human_size(num_bytes: int) -> str:
4257
for unit in ("B", "KB", "MB"):
4358
if num_bytes < 1024:
@@ -73,15 +88,17 @@ def main():
7388
stats = get_stats(po_file)
7489
rel_path = po_file.relative_to(root)
7590
size = po_file.stat().st_size
91+
marker = "* " if is_core(rel_path) else " "
7692
if stats is None:
77-
rows.append((str(rel_path), "FEHLER (Syntax)", -1.0, size))
93+
rows.append((marker + str(rel_path), "FEHLER (Syntax)", -1.0, size))
7894
continue
7995
total = stats["translated"] + stats["fuzzy"] + stats["untranslated"]
8096
pct = (stats["translated"] / total * 100) if total else 100.0
8197
label = f"{stats['translated']}/{total}"
82-
if stats["fuzzy"]:
83-
label += f" ({stats['fuzzy']} fuzzy)"
84-
rows.append((str(rel_path), label, pct, size))
98+
fuzzy_count = count_fuzzy_flags(po_file)
99+
if fuzzy_count:
100+
label += f" ({fuzzy_count} fuzzy)"
101+
rows.append((marker + str(rel_path), label, pct, size))
85102

86103
# Gesamtstatistik wird VOR dem --max-percent-Filter berechnet (über alle Dateien)
87104
complete_count = sum(1 for r in rows if r[2] >= 100.0)
@@ -105,7 +122,7 @@ def main():
105122
path_w = max(len(r[0]) for r in rows) + 2
106123
label_w = max(len(r[1]) for r in rows) + 2
107124

108-
print(f"{'Pfad':<{path_w}}{'Übersetzt':<{label_w}}{'%':>7} {'Größe':>8}")
125+
print(f"{' Pfad':<{path_w}}{'Übersetzt':<{label_w}}{'%':>7} {'Größe':>8}")
109126
print("-" * (path_w + label_w + 20))
110127
for rel_path, label, pct, size in rows:
111128
pct_str = " n/a" if pct < 0 else f"{pct:6.1f}%"
@@ -120,6 +137,7 @@ def main():
120137
print(f"Dateien mit Syntaxfehler: {error_count}")
121138
print(f"Gesamtstand über alle Dateien: {total_translated}/{total_strings} Strings "
122139
f"({overall_pct:.2f}%)")
140+
print("* = Pflichtdatei für den Sprachumschalter")
123141

124142

125143
if __name__ == "__main__":

0 commit comments

Comments
 (0)