From f9f3a526921c3dcc255cf63944290886b24da0f0 Mon Sep 17 00:00:00 2001 From: lovetox Date: Fri, 1 Apr 2022 20:33:41 +0200 Subject: [PATCH] Scripts: Update translation build script --- scripts/update_translations.py | 40 +++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/scripts/update_translations.py b/scripts/update_translations.py index 0af7493..9a292fa 100755 --- a/scripts/update_translations.py +++ b/scripts/update_translations.py @@ -3,21 +3,19 @@ import re import subprocess from pathlib import Path +import sys -TRANS_DIR = Path('po') +REPO_DIR = Path(__file__).parent.parent +TRANS_DIR = REPO_DIR / 'po' TRANS_TEMPLATE = TRANS_DIR / 'gajim_plugins.pot' -REPO_DIR = Path.cwd() +BUILD_DIR = REPO_DIR / 'plugins_translations' TRANSLATABLE_FILES = [ '*.py', '*.ui', ] -if not TRANS_DIR.exists(): - exit('Execute this script from the root dir') - - def template_is_equal(old_template_path: Path, new_template: str) -> bool: with open(old_template_path, 'r') as f: old_template = f.read() @@ -78,5 +76,31 @@ def update_translation_files() -> None: check=True) -update_translation_template() -update_translation_files() +def build_translations() -> None: + for po_file in TRANS_DIR.glob('*.po'): + lang = po_file.stem + po_file = TRANS_DIR / f'{lang}.po' + mo_file = BUILD_DIR / f'{po_file.stem}.mo' + + subprocess.run(['msgfmt', + str(po_file), + '-o', + str(mo_file)], + cwd=REPO_DIR, + check=True) + + +if __name__ == '__main__': + + build = False + if len(sys.argv) > 1: + cmd = sys.argv[1] + if cmd == 'build': + build = True + else: + exit('Unknown commands found: %s' % sys.argv) + + update_translation_template() + update_translation_files() + if build: + build_translations()