diff options
author | Damien Picard <pioverfour> | 2022-07-20 12:04:38 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-07-20 12:05:07 +0300 |
commit | c48dc61749fbf2f118651bb757e186df72b85acf (patch) | |
tree | 377e9422943c4bc256c4a8c415106ac98ed26873 /release | |
parent | 92ca920c52b90dd5552fc43582b0a965d7d173bb (diff) |
I18n: fixes to add-on message extraction
This commit fixes several issues in add-ons UI messages extraction code:
- In multi-file modules, the script would crash because it tried to write to
the dir instead of a `translations.py` file;
- The add-on message extraction works by enabling the add-on, getting all
messages; disabling the add-on, getting all messages; then comparing the
two message sets. But often a bug happens where a class gets a
description from somewhere else in memory. I couldn’t debug that, so a
workaround is to check that the message isn’t a corrupted one before
removing it;
- `printf()` doesn't exist in Python and would crash the script;
- `self.src[self.settings.PARSER_PY_ID]` can be replaced by `self.py_file`
in class `I18n`, since a property exists to do that;
- At one point a generator was printed instead of its values, so let's
unpack the generator to get the values. Maybe the print could be
deleted entirely;
- Use SPDX license identifier instead of GPL license block, to be more in
line with other scripts from the codebase.
Reviewed By: mont29
Differential Revision: https://developer.blender.org/D15474
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bl_i18n_utils/bl_extract_messages.py | 7 | ||||
-rw-r--r-- | release/scripts/modules/bl_i18n_utils/utils.py | 36 |
2 files changed, 16 insertions, 27 deletions
diff --git a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py index 3edb5b445fe..bfc111dd3c1 100644 --- a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py +++ b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py @@ -962,7 +962,12 @@ def dump_addon_messages(module_name, do_checks, settings): # and make the diff! for key in minus_msgs: if key != settings.PO_HEADER_KEY: - del msgs[key] + if key in msgs: + del msgs[key] + else: + # This should not happen, but some messages seem to have + # leaked on add-on unregister and register? + print(f"Key not found in msgs: {key}") if check_ctxt: _diff_check_ctxt(check_ctxt, minus_check_ctxt) diff --git a/release/scripts/modules/bl_i18n_utils/utils.py b/release/scripts/modules/bl_i18n_utils/utils.py index b1e3fa07ac5..324c3ea261d 100644 --- a/release/scripts/modules/bl_i18n_utils/utils.py +++ b/release/scripts/modules/bl_i18n_utils/utils.py @@ -154,7 +154,7 @@ def get_po_files_from_dir(root_dir, langs=set()): else: continue if uid in found_uids: - printf("WARNING! {} id has been found more than once! only first one has been loaded!".format(uid)) + print("WARNING! {} id has been found more than once! only first one has been loaded!".format(uid)) continue found_uids.add(uid) yield uid, po_file @@ -1240,8 +1240,8 @@ class I18n: return os.path.join(os.path.dirname(path), uid + ".po") elif kind == 'PY': if not path.endswith(".py"): - if self.src.get(self.settings.PARSER_PY_ID): - return self.src[self.settings.PARSER_PY_ID] + if os.path.isdir(path): + return os.path.join(path, "translations.py") return os.path.join(os.path.dirname(path), "translations.py") return path @@ -1392,15 +1392,15 @@ class I18n: if langs set is void, all languages found are loaded. """ default_context = self.settings.DEFAULT_CONTEXT - self.src[self.settings.PARSER_PY_ID], msgs = self.check_py_module_has_translations(src, self.settings) + self.py_file, msgs = self.check_py_module_has_translations(src, self.settings) if msgs is None: - self.src[self.settings.PARSER_PY_ID] = src + self.py_file = src msgs = () for key, (sources, gen_comments), *translations in msgs: if self.settings.PARSER_TEMPLATE_ID not in self.trans: self.trans[self.settings.PARSER_TEMPLATE_ID] = I18nMessages(self.settings.PARSER_TEMPLATE_ID, settings=self.settings) - self.src[self.settings.PARSER_TEMPLATE_ID] = self.src[self.settings.PARSER_PY_ID] + self.src[self.settings.PARSER_TEMPLATE_ID] = self.py_file if key in self.trans[self.settings.PARSER_TEMPLATE_ID].msgs: print("ERROR! key {} is defined more than once! Skipping re-definitions!") continue @@ -1416,7 +1416,7 @@ class I18n: for uid, msgstr, (is_fuzzy, user_comments) in translations: if uid not in self.trans: self.trans[uid] = I18nMessages(uid, settings=self.settings) - self.src[uid] = self.src[self.settings.PARSER_PY_ID] + self.src[uid] = self.py_file comment_lines = [self.settings.PO_COMMENT_PREFIX + c for c in user_comments] + common_comment_lines self.trans[uid].msgs[key] = I18nMessage(ctxt, [key[1]], [msgstr], comment_lines, False, is_fuzzy, settings=self.settings) @@ -1479,7 +1479,7 @@ class I18n: if langs: translations &= langs translations = [('"' + lng + '"', " " * (len(lng) + 6), self.trans[lng]) for lng in sorted(translations)] - print(k for k in keys.keys()) + print(*(k for k in keys.keys())) for key in keys.keys(): if ref.msgs[key].is_commented: continue @@ -1565,25 +1565,9 @@ class I18n: # We completely replace the text found between start and end markers... txt = _gen_py(self, langs) else: - printf("Creating python file {} containing translations.".format(dst)) + print("Creating python file {} containing translations.".format(dst)) txt = [ - "# ***** BEGIN GPL LICENSE BLOCK *****", - "#", - "# This program is free software; you can redistribute it and/or", - "# modify it under the terms of the GNU General Public License", - "# as published by the Free Software Foundation; either version 2", - "# of the License, or (at your option) any later version.", - "#", - "# This program is distributed in the hope that it will be useful,", - "# but WITHOUT ANY WARRANTY; without even the implied warranty of", - "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", - "# GNU General Public License for more details.", - "#", - "# You should have received a copy of the GNU General Public License", - "# along with this program; if not, write to the Free Software Foundation,", - "# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.", - "#", - "# ***** END GPL LICENSE BLOCK *****", + "# SPDX-License-Identifier: GPL-2.0-or-later", "", self.settings.PARSER_PY_MARKER_BEGIN, "", |