I18n: make workspaces translatable
This makes workspaces more translatable: - New Workspace menu - header - preset menus - preset entries - workspace names upon factory file template load - new workspace name upon workspace addition To properly translate those names, an extraction function for workspace names from app templates was added as well. (Do not do anything when loading a user-saved file!) Reviewed By: mont29 Differential Revision: https://developer.blender.org/D15727
This commit is contained in:
parent
22fdb88be5
commit
4ac96a483b
|
@ -8,6 +8,7 @@ import datetime
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
import glob
|
||||
|
||||
# XXX Relative import does not work here when used from Blender...
|
||||
from bl_i18n_utils import settings as settings_i18n, utils
|
||||
|
@ -883,6 +884,29 @@ def dump_preset_messages(msgs, reports, 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)
|
||||
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! #####
|
||||
def dump_messages(do_messages, do_checks, settings):
|
||||
bl_ver = "Blender " + bpy.app.version_string
|
||||
|
@ -918,6 +942,9 @@ def dump_messages(do_messages, do_checks, settings):
|
|||
# Get strings from presets.
|
||||
dump_preset_messages(msgs, reports, settings)
|
||||
|
||||
# Get strings from startup templates.
|
||||
dump_template_messages(msgs, reports, settings)
|
||||
|
||||
# Get strings from addons' categories.
|
||||
for uid, label, tip in bpy.types.WindowManager.addon_filter.keywords['items'](
|
||||
bpy.context.window_manager,
|
||||
|
|
|
@ -519,6 +519,10 @@ REL_POTFILES_SOURCE_DIR = os.path.join("source")
|
|||
# Where to search for preset names (relative to SOURCE_DIR).
|
||||
REL_PRESETS_DIR = os.path.join("release", "scripts", "presets")
|
||||
|
||||
# Where to search for templates (relative to SOURCE_DIR).
|
||||
REL_TEMPLATES_DIR = os.path.join("release", "scripts", "startup",
|
||||
"bl_app_templates_system")
|
||||
|
||||
# The template messages file (relative to I18N_DIR).
|
||||
REL_FILE_NAME_POT = os.path.join(REL_BRANCHES_DIR, DOMAIN + ".pot")
|
||||
|
||||
|
@ -678,6 +682,7 @@ class I18nSettings:
|
|||
GIT_I18N_PO_DIR = property(*(_gen_get_set_path("GIT_I18N_ROOT", "REL_GIT_I18N_PO_DIR")))
|
||||
POTFILES_SOURCE_DIR = property(*(_gen_get_set_path("SOURCE_DIR", "REL_POTFILES_SOURCE_DIR")))
|
||||
PRESETS_DIR = property(*(_gen_get_set_path("SOURCE_DIR", "REL_PRESETS_DIR")))
|
||||
TEMPLATES_DIR = property(*(_gen_get_set_path("SOURCE_DIR", "REL_TEMPLATES_DIR")))
|
||||
FILE_NAME_POT = property(*(_gen_get_set_path("I18N_DIR", "REL_FILE_NAME_POT")))
|
||||
MO_PATH_ROOT = property(*(_gen_get_set_path("I18N_DIR", "REL_MO_PATH_ROOT")))
|
||||
MO_PATH_TEMPLATE = property(*(_gen_get_set_path("I18N_DIR", "REL_MO_PATH_TEMPLATE")))
|
||||
|
|
|
@ -359,6 +359,11 @@ static int workspace_append_activate_exec(bContext *C, wmOperator *op)
|
|||
BLO_LIBLINK_APPEND_RECURSIVE);
|
||||
|
||||
if (appended_workspace) {
|
||||
if (BLT_translate_new_dataname()) {
|
||||
/* Translate workspace name */
|
||||
BKE_libblock_rename(bmain, &appended_workspace->id, CTX_DATA_(BLT_I18NCONTEXT_ID_WORKSPACE, idname));
|
||||
}
|
||||
|
||||
/* Set defaults. */
|
||||
BLO_update_defaults_workspace(appended_workspace, NULL);
|
||||
|
||||
|
@ -442,7 +447,7 @@ static void workspace_append_button(uiLayout *layout,
|
|||
|
||||
PointerRNA opptr;
|
||||
uiItemFullO_ptr(
|
||||
layout, ot_append, workspace->id.name + 2, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
|
||||
layout, ot_append, CTX_DATA_(BLT_I18NCONTEXT_ID_WORKSPACE, workspace->id.name + 2), ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
|
||||
RNA_string_set(&opptr, "idname", id->name + 2);
|
||||
RNA_string_set(&opptr, "filepath", filepath);
|
||||
}
|
||||
|
@ -495,7 +500,8 @@ static void workspace_add_menu(bContext *UNUSED(C), uiLayout *layout, void *temp
|
|||
|
||||
static int workspace_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
{
|
||||
uiPopupMenu *pup = UI_popup_menu_begin(C, op->type->name, ICON_ADD);
|
||||
uiPopupMenu *pup = UI_popup_menu_begin(C, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT,
|
||||
op->type->name), ICON_ADD);
|
||||
uiLayout *layout = UI_popup_menu_layout(pup);
|
||||
|
||||
uiItemMenuF(layout, IFACE_("General"), ICON_NONE, workspace_add_menu, NULL);
|
||||
|
@ -507,7 +513,7 @@ static int workspace_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
|
|||
char *template = link->data;
|
||||
char display_name[FILE_MAX];
|
||||
|
||||
BLI_path_to_display_name(display_name, sizeof(display_name), template);
|
||||
BLI_path_to_display_name(display_name, sizeof(display_name), IFACE_(template));
|
||||
|
||||
/* Steals ownership of link data string. */
|
||||
uiItemMenuFN(layout, display_name, ICON_NONE, workspace_add_menu, template);
|
||||
|
|
|
@ -699,6 +699,13 @@ static void wm_file_read_post(bContext *C, const struct wmFileReadPost_Params *p
|
|||
}
|
||||
}
|
||||
|
||||
if (is_factory_startup && BLT_translate_new_dataname()) {
|
||||
/* Translate workspace names */
|
||||
LISTBASE_FOREACH_MUTABLE (WorkSpace *, workspace, &bmain->workspaces) {
|
||||
BKE_libblock_rename(bmain, &workspace->id, CTX_DATA_(BLT_I18NCONTEXT_ID_WORKSPACE, workspace->id.name + 2));
|
||||
}
|
||||
}
|
||||
|
||||
if (use_data) {
|
||||
/* important to do before NULL'ing the context */
|
||||
BKE_callback_exec_null(bmain, BKE_CB_EVT_VERSION_UPDATE);
|
||||
|
|
Loading…
Reference in New Issue