1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/env python3
import re
import sys
if len(sys.argv) != 2:
print(f"usage: {sys.argv[0]} POTFILE", file=sys.stderr)
sys.exit(1)
potfile = sys.argv[1]
failed = 0
def print_msg(files, msgs):
if len(msgs) == 0:
return
print("\n".join(files))
for m in msgs:
print(f" {m}")
global failed
failed += 1
with open(potfile, "r") as pot:
files = []
msgs = []
cFormat = False
for line in pot:
if not line or line.startswith("msgstr "):
print_msg(files, msgs)
files = []
msgs = []
cFormat = False
continue
if line.startswith("#: "):
files.extend(line[3:].split())
continue
if line.startswith("#,"):
cFormat = " c-format" in line
continue
m = re.search(r'^(msgid )?"(.*%[^%$ ]*[a-zA-Z].*)"', line)
if cFormat and m is not None:
msgs.append(m.group(2))
if failed:
print(f"Found {failed} messages without permutable format strings!",
file=sys.stderr)
sys.exit(1)
|