From a4be606a37da3ecd6f77cf08e1b3eaa14fc59d2f Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 29 Dec 2023 17:20:39 +0500 Subject: [PATCH] setup_translations - original dump_py_messages as we're going to monkey patch it and this commit is needed to keep the history of changes --- src/blenderbim/scripts/setup_translations.py | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/blenderbim/scripts/setup_translations.py b/src/blenderbim/scripts/setup_translations.py index e9b5374aca..69174546e9 100644 --- a/src/blenderbim/scripts/setup_translations.py +++ b/src/blenderbim/scripts/setup_translations.py @@ -3,6 +3,8 @@ import addon_utils import shutil import tempfile import importlib +import os +import bl_i18n_utils from pathlib import Path context = bpy.context @@ -79,6 +81,33 @@ def update_translations_from_po(): bpy.app.translations.register(ADDON_NAME, translations_module.translations_dict) +def dump_py_messages(msgs, reports, addons, settings, addons_only=False): + def _get_files(path): + if not os.path.exists(path): + return [] + if os.path.isdir(path): + return [os.path.join(dpath, fn) for dpath, _, fnames in os.walk(path) for fn in fnames + if fn.endswith(".py") and (fn == "__init__.py" + or not fn.startswith("_"))] + return [path] + + files = [] + if not addons_only: + for path in settings.CUSTOM_PY_UI_FILES: + for root in (bpy.utils.resource_path(t) for t in ("USER", "LOCAL", "SYSTEM")): + files += _get_files(os.path.join(root, path)) + + # Add all given addons. + for mod in addons: + fn = mod.__file__ + if os.path.basename(fn) == "__init__.py": + files += _get_files(os.path.dirname(fn)) + else: + files.append(fn) + + bl_i18n_utils.bl_extract_messages.dump_py_messages_from_files(msgs, reports, sorted(files), settings) + + if __name__ == "__main__": if not is_addon_loaded("ui_translate"): raise Exception('"Manage UI translations" addon is not enabled')