Skip to content

Commit a868b6a

Browse files
committed
pdk coverage
1 parent 6237989 commit a868b6a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

.pdk/pdk/__init__.py

+35
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,41 @@ def find_obsoletes(self, *, delete=False):
132132
relpath.unlink()
133133
relpath.with_suffix(".mo").unlink(missing_ok=True)
134134

135+
def coverage(self):
136+
"""Calculate translation coverage."""
137+
os.chdir(MSG_DIR)
138+
total = translated = fuzzy = 0
139+
items = []
140+
for root, _, files in os.walk("."):
141+
for filename in files:
142+
if not filename.endswith(".po"):
143+
continue
144+
path = pathlib.Path(root, filename)
145+
if str(path) == "whatsnew/changelog.po":
146+
continue
147+
with path.open() as f:
148+
catalog = read_po(f, abort_invalid=True)
149+
file_total = file_translated = file_fuzzy = 0
150+
for msg in catalog:
151+
if not msg.id:
152+
continue
153+
file_total += len(msg.id)
154+
if not msg.fuzzy and msg.string:
155+
file_translated += len(msg.id)
156+
elif msg.fuzzy:
157+
file_fuzzy += len(msg.id)
158+
total += file_total
159+
translated += file_translated
160+
fuzzy += file_fuzzy
161+
items.append((file_total - file_translated, path))
162+
for remaining, path in sorted(items):
163+
if remaining:
164+
print(f"{remaining:7d} {path}")
165+
print(f"{total - translated:7d} Remaining")
166+
print(f"{fuzzy:7d} Fuzzy")
167+
print(f"{total:7d} Total")
168+
print(f"{translated * 100.0 / total:.2f}%")
169+
135170

136171
def main():
137172
fire.Fire(Command)

0 commit comments

Comments
 (0)