diff options
author | lovetox <philipp@hoerist.com> | 2022-04-01 21:33:41 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2022-04-01 21:33:41 +0300 |
commit | f9f3a526921c3dcc255cf63944290886b24da0f0 (patch) | |
tree | d7ad8f9c855a333f8e77912a79271c85e358cd98 | |
parent | 658b7ea1045da8cc30999139528ac00a37710b71 (diff) |
Scripts: Update translation build script
-rwxr-xr-x | scripts/update_translations.py | 40 |
1 files 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() |