I18n: Translate missing node add search menu items

Some items in the node editors' add menus were not properly
translated. The affected items referenced an enum property on a node,
such as Math node's Operation.

Since some of those enums use a specific translation context, the same
context must be used when adding them to the search menus. The context
can simply be retrieved from the bl_rna prop itself.

In addition, some items use labels that are already translated
manually and do not need the auto translation, so disable that in
those cases (translate=False).

No new messages are added by this change.

Reported by Ye Gui in #43295.

Pull Request: https://projects.blender.org/blender/blender/pulls/141629
This commit is contained in:
Damien Picard
2025-07-09 12:00:36 +02:00
committed by Bastien Montagne
parent 23d06e9c9a
commit 7d4f6faffd

View File

@@ -40,7 +40,7 @@ def add_node_type_with_outputs(context, layout, node_type, subnames, *, label=No
if getattr(context, "is_menu_search", False):
for subname in subnames:
sublabel = "{}{}".format(iface_(label), iface_(subname))
item_props = add_node_type(layout, node_type, label=sublabel, search_weight=search_weight)
item_props = add_node_type(layout, node_type, label=sublabel, search_weight=search_weight, translate=False)
item_props.visible_output = subname
props.append(item_props)
return props
@@ -98,12 +98,14 @@ def add_node_type_with_searchable_enum(context, layout, node_idname, property_na
add_node_type(layout, node_idname, search_weight=search_weight)
if getattr(context, "is_menu_search", False):
node_type = getattr(bpy.types, node_idname)
translation_context = node_type.bl_rna.properties[property_name].translation_context
for item in node_type.bl_rna.properties[property_name].enum_items_static:
label = "{}{}".format(node_type.bl_rna.name, item.name)
label = "{}{}".format(iface_(node_type.bl_rna.name), iface_(item.name, translation_context))
props = add_node_type(
layout,
node_idname,
label=label,
translate=False,
search_weight=search_weight)
prop = props.settings.add()
prop.name = property_name
@@ -112,15 +114,16 @@ def add_node_type_with_searchable_enum(context, layout, node_idname, property_na
def add_color_mix_node(context, layout):
label = iface_("Mix Color")
props = node_add_menu.add_node_type(layout, "ShaderNodeMix", label=label)
props = node_add_menu.add_node_type(layout, "ShaderNodeMix", label=label, translate=False)
ops = props.settings.add()
ops.name = "data_type"
ops.value = "'RGBA'"
if getattr(context, "is_menu_search", False):
translation_context = bpy.types.ShaderNodeMix.bl_rna.properties["blend_type"].translation_context
for item in bpy.types.ShaderNodeMix.bl_rna.properties["blend_type"].enum_items_static:
sublabel = "{}{}".format(label, item.name)
props = node_add_menu.add_node_type(layout, "ShaderNodeMix", label=sublabel)
sublabel = "{}{}".format(label, iface_(item.name, translation_context))
props = node_add_menu.add_node_type(layout, "ShaderNodeMix", label=sublabel, translate=False)
prop = props.settings.add()
prop.name = "data_type"
prop.value = "'RGBA'"