Commit: f53221bff7ffdcfb3acf03389450ed5ffb8f7964
Author: Hans Goudey
Date:   Wed Mar 3 12:58:33 2021 -0600
Branches: master
https://developer.blender.org/rBf53221bff7ffdcfb3acf03389450ed5ffb8f7964

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.

===================================================================

M       source/blender/editors/space_node/node_draw.cc
M       source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
M       source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
M       source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
M       
source/blender/nodes/geometry/nodes/node_geo_subdivision_surface_simple.cc
M       source/blender/nodes/intern/node_geometry_exec.cc

===================================================================

diff --git a/source/blender/editors/space_node/node_draw.cc 
b/source/blender/editors/space_node/node_draw.cc
index 162f3878f7e..5a0cacf070b 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -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());
 }
 
diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc 
b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
index bb5b5073c32..27c35da7d37 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
@@ -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;
     }
   }
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc 
b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index d9878d54353..c40cb2bb0ae 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -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;
   }
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc 
b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
index 669b5ee4614..dbbb73bd36d 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
@@ -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;
   }
 
diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface_simple.cc 
b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface_simple.cc
index 2a0cb727cd6..38560d277e3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface_simple.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface_simple.cc
@@ -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
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc 
b/source/blender/nodes/intern/node_geometry_exec.cc
index a2e0a4dd6a4..9e62b7d7312 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -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);
   }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to