UI: Allow translation for node error messages

This commit exposes the strings used in the node error messages for
localization. It also changes the message tooltip creation to
automatically add the period at the end, to be more consistent with
the (arguably bad) design of other tooltips in Blender.

Calling `TIP_` directly in the node implementation files allows us to
continue using `std::string` concatenation instead of passing variadic
arguments. It's also more explicit about which part of the message is
translated and which isn't. The files already include the translation
header anyway.
This commit is contained in:
Hans Goudey 2021-03-03 12:58:33 -06:00
parent 93cdf461f3
commit f53221bff7
Notes: blender-bot 2023-02-14 06:57:56 +01:00
Referenced by issue #85774, Support translation in node error messages
6 changed files with 10 additions and 11 deletions

View File

@ -1236,16 +1236,15 @@ static char *node_errors_tooltip_fn(bContext *UNUSED(C), void *argN, const char
for (const NodeWarning &warning : warnings.drop_back(1)) {
complete_string += warning.message;
/* Adding the period is not ideal for multi-line messages, but it is consistent
* with other tooltip implementations in Blender, so it is added here. */
complete_string += '.';
complete_string += '\n';
}
/* Let the tooltip system automatically add the last period. */
complete_string += warnings.last().message;
/* Remove the last period-- the tooltip system adds this automatically. */
if (complete_string.back() == '.') {
complete_string.pop_back();
}
return BLI_strdupn(complete_string.c_str(), complete_string.size());
}

View File

@ -224,7 +224,7 @@ static void randomize_attribute_on_component(GeometryComponent &component,
if (operation != GEO_NODE_ATTRIBUTE_RANDOMIZE_REPLACE_CREATE) {
if (!component.attribute_exists(attribute_name)) {
params.error_message_add(NodeWarningType::Error,
"No attribute with name '" + attribute_name + "'.");
TIP_("No attribute with name \"") + attribute_name + "\"");
return;
}
}

View File

@ -429,7 +429,7 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
params.node().custom1);
if (!geometry_set.has_mesh()) {
params.error_message_add(NodeWarningType::Error, "Geometry must contain a mesh.");
params.error_message_add(NodeWarningType::Error, TIP_("Geometry must contain a mesh"));
params.set_output("Geometry", std::move(geometry_set_out));
return;
}
@ -446,7 +446,7 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
const Mesh *mesh_in = mesh_component.get_for_read();
if (mesh_in->mpoly == nullptr) {
params.error_message_add(NodeWarningType::Error, "Mesh has no faces.");
params.error_message_add(NodeWarningType::Error, TIP_("Mesh has no faces"));
params.set_output("Geometry", std::move(geometry_set_out));
return;
}

View File

@ -103,7 +103,7 @@ static void get_instanced_data__collection(
if (BLI_listbase_is_empty(&collection->children) &&
BLI_listbase_is_empty(&collection->gobject)) {
params.error_message_add(NodeWarningType::Info, "Collection is empty.");
params.error_message_add(NodeWarningType::Info, TIP_("Collection is empty"));
return;
}

View File

@ -49,7 +49,7 @@ static void geo_node_subdivision_surface_simple_exec(GeoNodeExecParams params)
#ifndef WITH_OPENSUBDIV
params.error_message_add(NodeWarningType::Error,
"Disabled, Blender was built without OpenSubdiv");
TIP_("Disabled, Blender was built without OpenSubdiv"));
params.set_output("Geometry", std::move(geometry_set));
return;
#endif

View File

@ -79,7 +79,7 @@ ReadAttributePtr GeoNodeExecParams::get_input_attribute(const StringRef name,
* the domain is empty and we don't expect an attribute anyway). */
if (!name.empty() && component.attribute_domain_size(domain) != 0) {
this->error_message_add(NodeWarningType::Error,
std::string("No attribute with name '") + name + "'.");
TIP_("No attribute with name \"") + name + "\"");
}
return component.attribute_get_constant_for_read(domain, type, default_value);
}