From f8ca92279d9eb9e150e1b4554a83ceef06f57352 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 9 Jan 2024 16:54:58 +0500 Subject: [PATCH] monkey patch blender's dump_addon_messages The way blender gather messages to translate is: 1) disable the addon 2) parse all available strings 3) enable the addon 4) parse all strings available strings again and subtract the ones gathered at step 2. But due Blender bug (https://projects.blender.org/blender/blender/issues/116579) not all addon parts unregistered at step 1, so some addon's strings left out and gathered at step 2 and then subtracted at step 4. At the end, we loose them and they will be missing from resulting translations files. I've monkey patched dump_addon_messages so it now works a bit more safe: 0) It expects addon to be disabled and Blender restarted after 1) Gather all Blender strings 2) Enable addon 3) Gather all Blender strings again and subtract strings from step 1. --- src/blenderbim/scripts/setup_translations.py | 30 +++++++------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/blenderbim/scripts/setup_translations.py b/src/blenderbim/scripts/setup_translations.py index 18d4ced15c..8cb2ee0955 100644 --- a/src/blenderbim/scripts/setup_translations.py +++ b/src/blenderbim/scripts/setup_translations.py @@ -138,14 +138,8 @@ def dump_addon_messages(module_name, do_checks, settings): print_info, ) - # Get current addon state (loaded or not): - was_loaded = addon_utils.check(module_name)[1] - # Enable our addon. - addon = utils.enable_addons(addons={module_name})[0] - - addon_info = addon_utils.module_bl_info(addon) - ver = addon_info["name"] + " " + ".".join(str(v) for v in addon_info["version"]) + ver = module_name rev = 0 date = datetime.datetime.now() pot = utils.I18nMessages.gen_empty_messages( @@ -161,24 +155,20 @@ def dump_addon_messages(module_name, do_checks, settings): check_ctxt = _gen_check_ctxt(settings) if do_checks else None minus_check_ctxt = _gen_check_ctxt(settings) if do_checks else None - # Get strings from RNA, our addon being enabled. - print("A") - reports = _gen_reports(check_ctxt) - print("B") - dump_rna_messages(msgs, reports, settings) - print("C") - - # Now disable our addon, and re-scan RNA. - utils.enable_addons(addons={module_name}, disable=True) + # Get strings from RNA, our addon being disabled print("D") - reports["check_ctxt"] = minus_check_ctxt + reports = _gen_reports(check_ctxt) print("E") dump_rna_messages(minus_msgs, reports, settings) print("F") - # Restore previous state if needed! - if was_loaded: - utils.enable_addons(addons={module_name}) + # Now enable our addon, and re-scan RNA. + addon = utils.enable_addons(addons={module_name})[0] + print("A") + reports["check_ctxt"] = minus_check_ctxt + print("B") + dump_rna_messages(msgs, reports, settings) + print("C") # and make the diff! for key in minus_msgs: