From 12123d6d52987bfde261695ea42c8707d0717735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 15 Nov 2022 15:31:49 +0000 Subject: [PATCH] languages: create new script update_po.py The script should do the same work as when one run update_po.sh The Python script can be run on Windows too. --- lang/update-po.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lang/update-po.py diff --git a/lang/update-po.py b/lang/update-po.py new file mode 100644 index 000000000..1a710b04e --- /dev/null +++ b/lang/update-po.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +""" +Portable script to update po files on most platforms +Make sure the .pot file is up-to-date first by +by calling within the ./po folder: +python ../lang-extract.py --no-missing -s -o Firmware.pot ../../Firmware/[a-zA-Z]*.[ch]* ../../Firmware/mmu2/[a-zA-Z]*.[ch]* +""" + +import sys +from pathlib import Path +import polib +from polib import POFile + +BASE_DIR: Path = Path.cwd() +PO_DIR: Path = BASE_DIR / "po" +PO_FILE_LIST: list[Path] = [] +POT_REFERENCE: POFile = polib.pofile(PO_DIR/'Firmware.pot') + + +def main(): + PO_FILE_LIST = sorted(PO_DIR.glob('**/*.po')) + + for po_file in PO_FILE_LIST: + po = polib.pofile(po_file) + po.merge(POT_REFERENCE) + po.save(po_file) + + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + sys.exit(-1)