forked from python/python-docs-tr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglossary.py
More file actions
46 lines (35 loc) · 1.02 KB
/
glossary.py
File metadata and controls
46 lines (35 loc) · 1.02 KB
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
#!/usr/bin/env python3
import os
import argparse
import regex
import polib
from glob import glob
from tabulate import tabulate
from textwrap import fill
def find_in_po(pattern):
table = []
try:
_, columns = os.popen("stty size", "r").read().split()
available_width = int(columns) // 2 - 3
except Exception:
available_width = 80 // 2 - 3
for file in glob("**/*.po"):
pofile = polib.pofile(file)
table.extend(
[
fill(entry.msgid, width=available_width),
fill(entry.msgstr, width=available_width),
]
for entry in pofile
if entry.msgstr and regex.search(pattern, entry.msgid)
)
print(tabulate(table, tablefmt="fancy_grid"))
def parse_args():
parser = argparse.ArgumentParser(description="Find translated words.")
parser.add_argument("pattern")
return parser.parse_args()
def main():
args = parse_args()
find_in_po(args.pattern)
if __name__ == "__main__":
main()