Fix node UI not using translation context correctly.
Now that some node types may have custom context, we need to handle that in the (convoluted :| ) UI code of nodes as well. Reported in T43295 by Gabriel Gazzán (@gab3d), thanks.
This commit is contained in:
@@ -61,13 +61,19 @@ class NodeItem:
|
|||||||
# if no custom label is defined, fall back to the node type UI name
|
# if no custom label is defined, fall back to the node type UI name
|
||||||
return getattr(bpy.types, self.nodetype).bl_rna.name
|
return getattr(bpy.types, self.nodetype).bl_rna.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def translation_context(self):
|
||||||
|
if self._label:
|
||||||
|
return bpy.app.translations.contexts.default
|
||||||
|
else:
|
||||||
|
# if no custom label is defined, fall back to the node type UI name
|
||||||
|
return getattr(bpy.types, self.nodetype).bl_rna.translation_context
|
||||||
|
|
||||||
# NB: is a staticmethod because called with an explicit self argument
|
# NB: is a staticmethod because called with an explicit self argument
|
||||||
# NodeItemCustom sets this as a variable attribute in __init__
|
# NodeItemCustom sets this as a variable attribute in __init__
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def draw(self, layout, context):
|
def draw(self, layout, context):
|
||||||
default_context = bpy.app.translations.contexts.default
|
props = layout.operator("node.add_node", text=self.label, text_ctxt=self.translation_context)
|
||||||
|
|
||||||
props = layout.operator("node.add_node", text=self.label, text_ctxt=default_context)
|
|
||||||
props.type = self.nodetype
|
props.type = self.nodetype
|
||||||
props.use_transform = True
|
props.use_transform = True
|
||||||
|
|
||||||
|
@@ -3174,12 +3174,20 @@ void nodeSynchronizeID(bNode *node, bool copy_to_id)
|
|||||||
|
|
||||||
void nodeLabel(bNodeTree *ntree, bNode *node, char *label, int maxlen)
|
void nodeLabel(bNodeTree *ntree, bNode *node, char *label, int maxlen)
|
||||||
{
|
{
|
||||||
if (node->label[0] != '\0')
|
if (node->label[0] != '\0') {
|
||||||
BLI_strncpy(label, node->label, maxlen);
|
BLI_strncpy(label, node->label, maxlen);
|
||||||
else if (node->typeinfo->labelfunc)
|
}
|
||||||
|
else if (node->typeinfo->labelfunc) {
|
||||||
node->typeinfo->labelfunc(ntree, node, label, maxlen);
|
node->typeinfo->labelfunc(ntree, node, label, maxlen);
|
||||||
else
|
}
|
||||||
BLI_strncpy(label, IFACE_(node->typeinfo->ui_name), maxlen);
|
else {
|
||||||
|
/* Kind of hacky and weak... Ideally would be better to use RNA here. :| */
|
||||||
|
const char *tmp = CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, node->typeinfo->ui_name);
|
||||||
|
if (tmp == node->typeinfo->ui_name) {
|
||||||
|
tmp = IFACE_(node->typeinfo->ui_name);
|
||||||
|
}
|
||||||
|
BLI_strncpy(label, tmp, maxlen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void node_type_base_defaults(bNodeType *ntype)
|
static void node_type_base_defaults(bNodeType *ntype)
|
||||||
|
Reference in New Issue
Block a user