From 46644c1a66790a25ee2356a6ef66f84486c3cc98 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 6 May 2020 14:20:24 +0200 Subject: [PATCH] Adapt the percentage script to print per-file When an argument is passed, the script print percentage per-file. --- scripts/print_percentage.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/print_percentage.py b/scripts/print_percentage.py index 1f38fe8e62..38cc7fdcaf 100644 --- a/scripts/print_percentage.py +++ b/scripts/print_percentage.py @@ -2,6 +2,7 @@ import glob import os +import sys import polib # fades @@ -12,12 +13,26 @@ )) +def get_percent_translated(pofilename): + po = polib.pofile(pofilename) + file_per = po.percent_translated() + return file_per + + def main(): - for pofilename in glob.glob(PO_DIR + '**/tutorial/*.po'): - po = polib.pofile(pofilename) - file_per = po.percent_translated() + pofilename = None + if len(sys.argv) == 2: + pofilename = sys.argv[1] + + if pofilename: + file_per = get_percent_translated(pofilename) print(f"{pofilename} ::: {file_per}%") + else: + for pofilename in glob.glob(PO_DIR + '**/tutorial/*.po'): + file_per = get_percent_translated(pofilename) + print(f"{pofilename} ::: {file_per}%") + if __name__ == "__main__": main()