Skip to content

Commit bf5ca8a

Browse files
committed
PrefsDialog: Language completeness percentage
1 parent c249aec commit bf5ca8a

3 files changed

Lines changed: 31 additions & 43 deletions

File tree

gitfourchette/assets/lang/wip.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
cs
2-
it
3-
es
4-
ru
1+
cs 4
2+
es 37
3+
fr 100
4+
it 43
5+
ru 3
6+
zh_Hans 78

gitfourchette/forms/prefsdialog.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -400,33 +400,24 @@ def languageControl(self, prefKey: str, prefValue: str):
400400
control.addItem(defaultCaption, userData="")
401401
control.insertSeparator(1)
402402

403-
wipLocales = Path(QFile("assets:lang/wip.txt").fileName()).read_text().strip().splitlines()
403+
localeRatios = {}
404+
for wipLine in Path(QFile("assets:lang/wip.txt").fileName()).read_text().strip().splitlines():
405+
code, ratio = wipLine.split(" ")
406+
localeRatios[code] = ratio
407+
localeRatios["en"] = "100"
404408

405409
langDir = QDir("assets:lang", "*.mo")
406410
localeCodes = [f.removesuffix(".mo") for f in langDir.entryList()]
407-
408-
if not localeCodes: # pragma: no cover
409-
control.addItem("Translation files missing!")
410-
missingItem: QStandardItem = control.model().item(control.count() - 1)
411-
missingItem.setFlags(missingItem.flags() & ~Qt.ItemFlag.ItemIsEnabled)
412-
413411
assert "en" not in localeCodes, "English shouldn't have an .mo file"
414412
localeCodes.append("en")
415413

416414
localeNames = {code: QLocale(code).nativeLanguageName() for code in localeCodes}
417-
localeCodes.sort(key=lambda code: "AZ"[code in wipLocales] + localeNames[code].casefold())
415+
localeCodes.sort(key=lambda code: "0" if code == "en" else localeNames[code].casefold())
418416

419-
wipSeparatorInserted = False
420417
for code in localeCodes:
421418
name = localeNames[code]
422419
name = name[0].upper() + name[1:] # Many languages don't capitalize their name
423-
424-
if code in wipLocales:
425-
name = f"[WIP] {name}"
426-
if not wipSeparatorInserted:
427-
control.insertSeparator(control.count())
428-
wipSeparatorInserted = True
429-
420+
name = f"{name} ({localeRatios.get(code, '--')}%)"
430421
control.addItem(name, code)
431422

432423
control.setCurrentIndex(control.findData(prefValue))

update_resources.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import json
1313
import os
1414
import re
15+
import shlex
1516
import subprocess
1617
import sys
1718
import textwrap
@@ -84,21 +85,13 @@ def makeParser():
8485

8586

8687
def call(*args, **kwargs) -> subprocess.CompletedProcess:
87-
cmdstr = ""
88-
for token in args:
89-
cmdstr += " "
90-
if " " in token:
91-
cmdstr += F"\"{token}\""
92-
else:
93-
cmdstr += token
94-
print(F">{cmdstr}")
95-
88+
print(f"> {shlex.join(args)}")
9689
capture_output = kwargs.pop("capture_output", True)
9790
check = kwargs.pop("check", True)
9891
try:
9992
return subprocess.run(args, encoding='utf-8', capture_output=capture_output, check=check, **kwargs)
10093
except subprocess.CalledProcessError as e:
101-
print(F"Aborting setup because: {e}")
94+
print(f"Aborting: {e}")
10295
sys.exit(1)
10396

10497

@@ -294,6 +287,7 @@ def updatePoFiles():
294287
"--update",
295288
"--sort-by-file",
296289
"--no-wrap",
290+
"--backup=off",
297291
str(poPath),
298292
LANG_TEMPLATE,
299293
capture_output=False)
@@ -316,29 +310,30 @@ def compileMoFiles():
316310
""" Generate .mo files from .po files """
317311
wipLanguages = []
318312

319-
for poPath in Path(LANG_DIR).glob("*.po"):
313+
def extractStderrNumber(pattern, stderr):
314+
match = re.search(pattern, stderr)
315+
return int(match.group(1)) if match else 0
316+
317+
for poPath in sorted(Path(LANG_DIR).glob("*.po")):
320318
moPath: Path = poPath.with_suffix(".mo")
321319

322-
call("msgfmt", "-o", str(moPath), str(poPath), capture_output=False)
320+
msgfmt = call("msgfmt", "--no-hash", "--statistics", "-o", str(moPath), str(poPath),
321+
env={"LANGUAGE": "C"}, capture_output=True)
323322

324-
moSizeKB = moPath.stat().st_size // 1024
323+
complete = extractStderrNumber(r"(\d+) translated messages", msgfmt.stderr)
324+
missing1 = extractStderrNumber(r"(\d+) fuzzy translations", msgfmt.stderr)
325+
missing2 = extractStderrNumber(r"(\d+) untranslated messages", msgfmt.stderr)
326+
ratio = round(100.0 * complete / (complete + missing1 + missing2))
327+
print(f" {poPath.stem}: {ratio}% complete | {msgfmt.stderr.strip()}")
325328

326329
# Remove empty po/mo files
327-
if moSizeKB == 0:
330+
if ratio <= 0:
328331
print(f"*** Removing empty translation '{poPath.name}'")
329332
poPath.unlink()
330333
moPath.unlink()
331334
continue
332335

333-
# Small .mo files are considered stubs and won't be included in builds
334-
if moSizeKB < 5:
335-
print(f"*** Removing '{moPath.name}' -- looks like a stub ({moSizeKB} KB)")
336-
moPath.unlink()
337-
continue
338-
339-
# .mo files below 100 KB are considered incomplete
340-
if moSizeKB < 100:
341-
wipLanguages += [moPath.stem]
336+
wipLanguages += [f"{moPath.stem} {ratio}"]
342337

343338
Path(LANG_DIR, "wip.txt").write_text("\n".join(wipLanguages) + "\n")
344339

0 commit comments

Comments
 (0)