Created
October 5, 2018 10:17
-
-
Save JulienPalard/c430ac23446da2081060ab17bf006ac1 to your computer and use it in GitHub Desktop.
Find a word in msgids, show msgstrs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
from glob import glob | |
import os | |
from textwrap import fill | |
import regex | |
import polib | |
from tabulate import tabulate | |
def find_in_po(pattern): | |
table = [] | |
try: | |
_, columns = os.popen("stty size", "r").read().split() | |
available_width = int(columns) // 2 - 3 | |
except: | |
available_width = 80 // 2 - 3 | |
for file in glob("**/*.po"): | |
pofile = polib.pofile(file) | |
for entry in pofile: | |
if entry.msgstr and regex.search(pattern, entry.msgid): | |
table.append( | |
[ | |
fill(entry.msgid, width=available_width), | |
fill(entry.msgstr, width=available_width), | |
] | |
) | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment