Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
| # SPDX-License-Identifier: GPL-2.0-or-later | # SPDX-License-Identifier: GPL-2.0-or-later | ||||
| # Populate a template file (POT format currently) from Blender RNA/py/C data. | # Populate a template file (POT format currently) from Blender RNA/py/C data. | ||||
| # XXX: This script is meant to be used from inside Blender! | # XXX: This script is meant to be used from inside Blender! | ||||
| # You should not directly use this script, rather use update_msg.py! | # You should not directly use this script, rather use update_msg.py! | ||||
| import datetime | import datetime | ||||
| import os | import os | ||||
| import re | import re | ||||
| import sys | import sys | ||||
| import glob | |||||
| # XXX Relative import does not work here when used from Blender... | # XXX Relative import does not work here when used from Blender... | ||||
| from bl_i18n_utils import settings as settings_i18n, utils | from bl_i18n_utils import settings as settings_i18n, utils | ||||
| import bpy | import bpy | ||||
| ##### Utils ##### | ##### Utils ##### | ||||
| ▲ Show 20 Lines • Show All 859 Lines • ▼ Show 20 Lines | for dpath, _, fnames in os.walk(settings.PRESETS_DIR): | ||||
| files.append(rel_path) | files.append(rel_path) | ||||
| for rel_path in sorted(files): | for rel_path in sorted(files): | ||||
| msgsrc, msgid = os.path.split(rel_path) | msgsrc, msgid = os.path.split(rel_path) | ||||
| msgsrc = "Preset from " + msgsrc | msgsrc = "Preset from " + msgsrc | ||||
| msgid = bpy.path.display_name(msgid, title_case=False) | msgid = bpy.path.display_name(msgid, title_case=False) | ||||
| process_msg(msgs, settings.DEFAULT_CONTEXT, msgid, msgsrc, reports, None, settings) | process_msg(msgs, settings.DEFAULT_CONTEXT, msgid, msgsrc, reports, None, settings) | ||||
| def dump_template_messages(msgs, reports, settings): | |||||
| bfiles = [""] # General template, no name needed | |||||
| bfiles += glob.glob(settings.TEMPLATES_DIR + "/**/*.blend", recursive=True) | |||||
| workspace_names = {} | |||||
| for bfile in bfiles: | |||||
| template = os.path.dirname(bfile) | |||||
| template = os.path.basename(template) | |||||
| bpy.ops.wm.read_homefile(use_factory_startup=True, app_template=template) | |||||
mont29: Not sure why this line is needed??? | |||||
Done Inline ActionsOh right, I forgot to remove that when I thought I needed to use a blend file. Thanks! pioverfour: Oh right, I forgot to remove that when I thought I needed to use a blend file. Thanks! | |||||
| for ws in bpy.data.workspaces: | |||||
| names = workspace_names.setdefault(ws.name, []) | |||||
| names.append(template or "General") | |||||
| from bpy.app.translations import contexts as i18n_contexts | |||||
| msgctxt = i18n_contexts.id_workspace | |||||
| for workspace_name in sorted(workspace_names): | |||||
| for msgsrc in sorted(workspace_names[workspace_name]): | |||||
| msgsrc = "Workspace from template " + msgsrc | |||||
| process_msg(msgs, msgctxt, workspace_name, msgsrc, | |||||
| reports, None, settings) | |||||
| ##### Main functions! ##### | ##### Main functions! ##### | ||||
| def dump_messages(do_messages, do_checks, settings): | def dump_messages(do_messages, do_checks, settings): | ||||
| bl_ver = "Blender " + bpy.app.version_string | bl_ver = "Blender " + bpy.app.version_string | ||||
| bl_hash = bpy.app.build_hash | bl_hash = bpy.app.build_hash | ||||
| bl_date = datetime.datetime.strptime(bpy.app.build_date.decode() + "T" + bpy.app.build_time.decode(), | bl_date = datetime.datetime.strptime(bpy.app.build_date.decode() + "T" + bpy.app.build_time.decode(), | ||||
| "%Y-%m-%dT%H:%M:%S") | "%Y-%m-%dT%H:%M:%S") | ||||
| pot = utils.I18nMessages.gen_empty_messages(settings.PARSER_TEMPLATE_ID, bl_ver, bl_hash, bl_date, bl_date.year, | pot = utils.I18nMessages.gen_empty_messages(settings.PARSER_TEMPLATE_ID, bl_ver, bl_hash, bl_date, bl_date.year, | ||||
| settings=settings) | settings=settings) | ||||
| Show All 19 Lines | def dump_messages(do_messages, do_checks, settings): | ||||
| dump_py_messages(msgs, reports, addons, settings) | dump_py_messages(msgs, reports, addons, settings) | ||||
| # Get strings from C source code. | # Get strings from C source code. | ||||
| dump_src_messages(msgs, reports, settings) | dump_src_messages(msgs, reports, settings) | ||||
| # Get strings from presets. | # Get strings from presets. | ||||
| dump_preset_messages(msgs, reports, settings) | dump_preset_messages(msgs, reports, settings) | ||||
| # Get strings from startup templates. | |||||
| dump_template_messages(msgs, reports, settings) | |||||
| # Get strings from addons' categories. | # Get strings from addons' categories. | ||||
| for uid, label, tip in bpy.types.WindowManager.addon_filter.keywords['items']( | for uid, label, tip in bpy.types.WindowManager.addon_filter.keywords['items']( | ||||
| bpy.context.window_manager, | bpy.context.window_manager, | ||||
| bpy.context, | bpy.context, | ||||
| ): | ): | ||||
| process_msg(msgs, settings.DEFAULT_CONTEXT, label, "Add-ons' categories", reports, None, settings) | process_msg(msgs, settings.DEFAULT_CONTEXT, label, "Add-ons' categories", reports, None, settings) | ||||
| if tip: | if tip: | ||||
| process_msg(msgs, settings.DEFAULT_CONTEXT, tip, "Add-ons' categories", reports, None, settings) | process_msg(msgs, settings.DEFAULT_CONTEXT, tip, "Add-ons' categories", reports, None, settings) | ||||
| ▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines | |||||
Not sure why this line is needed???