diff --git a/scripts/modules/bl_i18n_utils/settings.py b/scripts/modules/bl_i18n_utils/settings.py index 2733c2e7fbd..d487c370b53 100644 --- a/scripts/modules/bl_i18n_utils/settings.py +++ b/scripts/modules/bl_i18n_utils/settings.py @@ -251,6 +251,14 @@ PYGETTEXT_KEYWORDS = (() + tuple(("{}\\((?:[^\"',]+,){{2}}\\s*" + _msg_re + r"\s*(?:\)|,)").format(it) for it in ("BKE_modifier_set_error",)) + + # Extract messages specific to node sockets declaring labels. + tuple(("{}\\((?:[^\"',]+,)\\s*" + _msg_re + r"\s*\)").format(it) + for it in ("node_sock_label",)) + + + # Same as above, but variant with a context. + tuple(("{}\\((?:[^\"',]+,)\\s*" + _msg_re + r"\s*,\s*" + _ctxt_re + r"\s*\)").format(it) + for it in ("node_sock_label",)) + + # This one is a tad more risky, but in practice would not expect a name/uid string parameter # (the second one in those functions) to ever have a comma in it, so think this is fine. tuple(("{}\\((?:[^,]+,){{2}}\\s*" + _msg_re + r"\s*(?:\)|,)").format(it) diff --git a/source/blender/blenkernel/BKE_node_runtime.hh b/source/blender/blenkernel/BKE_node_runtime.hh index afebe5c63ec..276727edebe 100644 --- a/source/blender/blenkernel/BKE_node_runtime.hh +++ b/source/blender/blenkernel/BKE_node_runtime.hh @@ -201,6 +201,7 @@ class bNodeSocketRuntime : NonCopyable, NonMovable { int index_in_node = -1; int index_in_all_sockets = -1; int index_in_inout_sockets = -1; + std::string label_translation_context; }; /** diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 963972c60af..6246b70a19a 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -191,6 +191,11 @@ namespace blender::ed::space_node { static const char *node_socket_get_translation_context(const bNodeSocket &socket) { + /* Get the context from the label if it is defined. */ + if (socket.runtime->label_translation_context[0] != '\0') { + return socket.runtime->label_translation_context.c_str(); + } + /* The node is not explicitly defined. */ if (socket.runtime->declaration == nullptr) { return nullptr; diff --git a/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc b/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc index 20a28b590d4..5fb70a0bc72 100644 --- a/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc +++ b/source/blender/nodes/composite/nodes/node_composite_sepcomb_color.cc @@ -2,6 +2,8 @@ #include "BLI_assert.h" +#include "BLT_translation.h" + #include "GPU_material.h" #include "COM_shader_node.hh" @@ -35,7 +37,7 @@ static void node_cmp_combsep_color_label(const ListBase *sockets, CMPNodeCombSep case CMP_NODE_COMBSEP_COLOR_HSV: node_sock_label(sock1, "Hue"); node_sock_label(sock2, "Saturation"); - node_sock_label(sock3, "Value"); + node_sock_label(sock3, "Value", BLT_I18NCONTEXT_COLOR); break; case CMP_NODE_COMBSEP_COLOR_HSL: node_sock_label(sock1, "Hue"); diff --git a/source/blender/nodes/intern/node_util.cc b/source/blender/nodes/intern/node_util.cc index 89b0e8e45bd..ade814293d6 100644 --- a/source/blender/nodes/intern/node_util.cc +++ b/source/blender/nodes/intern/node_util.cc @@ -73,9 +73,12 @@ void *node_initexec_curves(bNodeExecContext * /*context*/, bNode *node, bNodeIns /** \name Updates * \{ */ -void node_sock_label(bNodeSocket *sock, const char *name) +void node_sock_label(bNodeSocket *sock, const char *name, const char *translation_context) { STRNCPY(sock->label, name); + if (translation_context) { + sock->runtime->label_translation_context = translation_context; + } } void node_sock_label_clear(bNodeSocket *sock) @@ -83,6 +86,9 @@ void node_sock_label_clear(bNodeSocket *sock) if (sock->label[0] != '\0') { sock->label[0] = '\0'; } + if (sock->runtime->label_translation_context[0] != '\0') { + sock->runtime->label_translation_context[0] = '\0'; + } } void node_math_update(bNodeTree *ntree, bNode *node) @@ -262,7 +268,7 @@ void node_combsep_color_label(const ListBase *sockets, NodeCombSepColorMode mode case NODE_COMBSEP_COLOR_HSV: node_sock_label(sock1, "Hue"); node_sock_label(sock2, "Saturation"); - node_sock_label(sock3, "Value"); + node_sock_label(sock3, "Value", BLT_I18NCONTEXT_COLOR); break; default: { BLI_assert_unreachable(); diff --git a/source/blender/nodes/intern/node_util.hh b/source/blender/nodes/intern/node_util.hh index 735668187b7..fe920a94336 100644 --- a/source/blender/nodes/intern/node_util.hh +++ b/source/blender/nodes/intern/node_util.hh @@ -7,6 +7,8 @@ #pragma once +#include "BLT_translation.h" + struct bNode; struct bNodeTree; @@ -30,7 +32,9 @@ void node_copy_standard_storage(bNodeTree *dest_ntree, bNode *dest_node, const b void *node_initexec_curves(bNodeExecContext *context, bNode *node, bNodeInstanceKey key); /**** Updates ****/ -void node_sock_label(bNodeSocket *sock, const char *name); +void node_sock_label(bNodeSocket *sock, + const char *name, + const char *translation_context = BLT_I18NCONTEXT_DEFAULT); void node_sock_label_clear(bNodeSocket *sock); void node_math_update(bNodeTree *ntree, bNode *node);