From d20c9364efb01a513e14b5eb9195f51b9919c695 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sat, 14 Feb 2026 08:10:26 +0000 Subject: [PATCH] contrib/locale/push_locale: more deterministic messages.pot (fs order) Tries to remove differences caused by filesystem-order in the generated .pot file. The crowdin activity stream is full of events: ``` SomberNight_CI_BOT changed the context of 126 strings 02:42 String Previous context New context File Time {} blocks #: electrum/gui/qt/channel_details.py:256 #: electrum/gui/qt/channel_details.py:257 electrum/gui/qt/network_dialog.py:514 #: electrum/gui/qt/network_dialog.py:514 electrum/gui/qt/channel_details.py:256 #: electrum/gui/qt/channel_details.py:257 messages.pot 02:42 [...] ``` ^ i.e. on every CI push, the comments containing the file paths and line-numbers were getting mixed up randomly This is undesirable noise. --- .gitignore | 1 - contrib/locale/push_locale.py | 38 +++++++++++++++++------------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index e33d0cdd0..3ef1b05a9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ env/ .buildozer .buildozer_*/ bin/ -/app.fil .idea .mypy_cache .vscode diff --git a/contrib/locale/push_locale.py b/contrib/locale/push_locale.py index 18eb18f24..da7e84fbe 100755 --- a/contrib/locale/push_locale.py +++ b/contrib/locale/push_locale.py @@ -6,6 +6,7 @@ # Dependencies: # $ sudo apt-get install python3-requests gettext qt6-l10n-tools +import glob import os import subprocess import sys @@ -44,32 +45,31 @@ except (subprocess.CalledProcessError, OSError) as e1: except (subprocess.CalledProcessError, OSError) as e2: raise Exception("missing Qt lupdate/convert tools. Maybe try 'apt install qt6-l10n-tools'") - -cmd = "find electrum -type f -name '*.py' -o -name '*.kv'" -files = subprocess.check_output(cmd, shell=True) - -with open("app.fil", "wb") as f: - f.write(files) - -print("Found {} files to translate".format(len(files.splitlines()))) - -# Generate fresh translation template +# create build dir build_dir = os.path.join(locale_dir, "build") if not os.path.exists(build_dir): os.mkdir(build_dir) + +# add .py files +files_list = glob.glob("electrum/**/*.py", recursive=True) +files_list = sorted(files_list) # makes output deterministic across CI runs +with open(f"{build_dir}/app.fil", "w", encoding="utf-8") as f: + for item in files_list: + f.writelines(item + "\n") +print("Found {} .py files to translate".format(len(files_list))) + +# Generate fresh translation template print('Generating template...') -cmd = ["xgettext", "-s", "--from-code", "UTF-8", "--language", "Python", "--no-wrap", "-f", "app.fil", f"--output={build_dir}/messages_gettext.pot"] +cmd = ["xgettext", "-s", "--from-code", "UTF-8", "--language", "Python", "--no-wrap", "-f", f"{build_dir}/app.fil", f"--output={build_dir}/messages_gettext.pot"] subprocess.check_output(cmd) - # add QML translations -cmd = "find electrum/gui/qml -type f -name '*.qml'" -files = subprocess.check_output(cmd, shell=True) - -with open(f"{build_dir}/qml.lst", "wb") as f: - f.write(files) - -print("Found {} QML files to translate".format(len(files.splitlines()))) +files_list = glob.glob("electrum/gui/qml/**/*.qml", recursive=True) +files_list = sorted(files_list) # makes output deterministic across CI runs +with open(f"{build_dir}/qml.lst", "w", encoding="utf-8") as f: + for item in files_list: + f.write(item + "\n") +print("Found {} QML files to translate".format(len(files_list))) # note: lupdate writes relative paths into its output .ts file, relative to the .ts file itself :/ cmd = [QT_LUPDATE, f"@{build_dir}/qml.lst","-ts", f"{build_dir}/qml.ts"]