From 355bfe7e6730090d67cdf4e3cb4ca3c34dafd5a2 Mon Sep 17 00:00:00 2001 From: Gianluca Pernigotto Date: Sat, 13 Jul 2024 10:28:22 +0200 Subject: [PATCH] compile MO files using pyinstaller --- CHANGELOG | 1 + debian/changelog | 1 + develop/gettext_utils/babelutils.py | 25 +++++++++++++++++++++++++ develop/tools/pyinstaller_setup.py | 25 +++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 develop/gettext_utils/babelutils.py diff --git a/CHANGELOG b/CHANGELOG index f496dba9..60798c32 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,6 +20,7 @@ Sat, 13 July 2024 V.5.0.17 packages. * Added `babel` as a new dependency needed for compiling language catalogs when building binaries. + * Added compile MO files option before build standalone App using pyinstaller. +------------------------------------+ Wed, 03 July 2024 V.5.0.16 diff --git a/debian/changelog b/debian/changelog index 0b137881..5da73126 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,7 @@ videomass (5.0.17-1) UNRELEASED; urgency=medium packages. * Added `babel` as a new dependency needed for compiling language catalogs when building binaries. + * Added compile MO files option before build standalone App using pyinstaller. -- Gianluca Pernigotto Sat, 13 Jul 2024 12:00:00 +0200 diff --git a/develop/gettext_utils/babelutils.py b/develop/gettext_utils/babelutils.py new file mode 100644 index 00000000..bfb6aa7e --- /dev/null +++ b/develop/gettext_utils/babelutils.py @@ -0,0 +1,25 @@ +# Copyleft (c) Videomass Development Team. +# Distributed under the terms of the GPL3 License. + +import os +import sys +from babel.messages.frontend import compile_catalog + + +def build_translation_catalog(pathtolocale): + cmd = compile_catalog() + cmd.directory = pathtolocale + cmd.domain = "videomass" + cmd.statistics = True + cmd.finalize_options() + cmd.run() + +if __name__ == '__main__': + if not len(sys.argv) > 1: + sys.exit('ERROR: Please provide path to locale directory.') + + pathtolocale = sys.argv[1] + if os.path.exists(pathtolocale) and os.path.isdir(pathtolocale): + build = build_translation_catalog(pathtolocale) + else: + sys.exit(f'ERROR: Invalid pathname «{pathtolocale}».') diff --git a/develop/tools/pyinstaller_setup.py b/develop/tools/pyinstaller_setup.py index 0c4d4072..0b61cc29 100644 --- a/develop/tools/pyinstaller_setup.py +++ b/develop/tools/pyinstaller_setup.py @@ -28,6 +28,7 @@ import argparse import time import subprocess +from babel.messages.frontend import compile_catalog this = os.path.realpath(os.path.abspath(__file__)) HERE = os.path.dirname(os.path.dirname(os.path.dirname(this))) @@ -43,6 +44,28 @@ SPECFILE = os.path.join(HERE, f'{NAME}.spec') +def build_language_catalog(here=HERE): + """ + Before build standalone App make sure to compile + MO files for this macchine. + """ + while True: + quest = input('\nDo you want to compile MO files for ' + 'this macchine? (y/n)? ') + if quest.strip() in ('Y', 'y', 'n', 'N'): + break + print(f"\nInvalid option '{quest}'") + continue + + if quest in ('y', 'Y'): + cmd = compile_catalog() + cmd.directory = os.path.join(here, 'videomass', 'data', 'locale') + cmd.domain = "videomass" + cmd.statistics = True + cmd.finalize_options() + cmd.run() + + def videomass_data_source(here=HERE, name=NAME, release=about_app): """ Returns a dict object of the Videomass data @@ -415,6 +438,7 @@ def main(): get_data_platform() elif args.genspec_build: + build_language_catalog() get_data_platform() clean_buildingdirs() backup = backup_sources() @@ -424,6 +448,7 @@ def main(): restore_sources(backup) elif args.start_build: + build_language_catalog() clean_buildingdirs() backup = backup_sources() ret = make_portable()