I18n: add per-socket translation contexts for nodes
In order to properly translate UI messages, they sometimes need to be disambiguated using translation contexts. Until now, node sockets had no way to specify contexts and collisions occurred. This commit adds a way to declare contexts for each socket using: `.translation_context()` If no context is specified, the default null context is used. Pull Request #105195
This commit is contained in:
committed by
Hans Goudey
parent
61b457d390
commit
4dc59c7311
@@ -6,6 +6,7 @@ set(INC
|
||||
cached_resources
|
||||
../../blenkernel
|
||||
../../blenlib
|
||||
../../blentranslation
|
||||
../../gpu
|
||||
../../imbuf
|
||||
../../makesdna
|
||||
|
||||
@@ -181,6 +181,23 @@ void ED_node_tag_update_id(ID *id)
|
||||
|
||||
namespace blender::ed::space_node {
|
||||
|
||||
static const char *node_socket_get_translation_context(const bNodeSocket &socket)
|
||||
{
|
||||
/* The node is not explicitly defined. */
|
||||
if (socket.runtime->declaration == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
blender::StringRefNull translation_context = socket.runtime->declaration->translation_context;
|
||||
|
||||
/* Default context. */
|
||||
if (translation_context.is_empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return translation_context.data();
|
||||
}
|
||||
|
||||
static void node_socket_add_tooltip_in_node_editor(const bNodeTree &ntree,
|
||||
const bNodeSocket &sock,
|
||||
uiLayout &layout);
|
||||
@@ -380,8 +397,14 @@ static void node_update_basis(const bContext &C,
|
||||
/* Align output buttons to the right. */
|
||||
uiLayout *row = uiLayoutRow(layout, true);
|
||||
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
|
||||
|
||||
const char *socket_label = nodeSocketLabel(socket);
|
||||
socket->typeinfo->draw((bContext *)&C, row, &sockptr, &nodeptr, IFACE_(socket_label));
|
||||
const char *socket_translation_context = node_socket_get_translation_context(*socket);
|
||||
socket->typeinfo->draw((bContext *)&C,
|
||||
row,
|
||||
&sockptr,
|
||||
&nodeptr,
|
||||
CTX_IFACE_(socket_translation_context, socket_label));
|
||||
|
||||
node_socket_add_tooltip_in_node_editor(ntree, *socket, *row);
|
||||
|
||||
@@ -514,7 +537,12 @@ static void node_update_basis(const bContext &C,
|
||||
uiLayout *row = uiLayoutRow(layout, true);
|
||||
|
||||
const char *socket_label = nodeSocketLabel(socket);
|
||||
socket->typeinfo->draw((bContext *)&C, row, &sockptr, &nodeptr, IFACE_(socket_label));
|
||||
const char *socket_translation_context = node_socket_get_translation_context(*socket);
|
||||
socket->typeinfo->draw((bContext *)&C,
|
||||
row,
|
||||
&sockptr,
|
||||
&nodeptr,
|
||||
CTX_IFACE_(socket_translation_context, socket_label));
|
||||
|
||||
node_socket_add_tooltip_in_node_editor(ntree, *socket, *row);
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "BLI_string_ref.hh"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include "BLT_translation.h"
|
||||
|
||||
#include "DNA_node_types.h"
|
||||
|
||||
struct bNode;
|
||||
@@ -145,6 +147,7 @@ class SocketDeclaration {
|
||||
std::string name;
|
||||
std::string identifier;
|
||||
std::string description;
|
||||
std::string translation_context;
|
||||
/** Defined by whether the socket is part of the node's input or
|
||||
* output socket declaration list. Included here for convenience. */
|
||||
eNodeSocketInOut in_out;
|
||||
@@ -275,6 +278,12 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
|
||||
return *(Self *)this;
|
||||
}
|
||||
|
||||
Self &translation_context(std::string value = BLT_I18NCONTEXT_DEFAULT)
|
||||
{
|
||||
decl_->translation_context = std::move(value);
|
||||
return *(Self *)this;
|
||||
}
|
||||
|
||||
Self &no_muted_links(bool value = true)
|
||||
{
|
||||
decl_->no_mute_links = value;
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace blender::nodes::node_composite_keyingscreen_cc {
|
||||
|
||||
static void cmp_node_keyingscreen_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.add_output<decl::Color>(N_("Screen"));
|
||||
b.add_output<decl::Color>(CTX_N_(BLT_I18NCONTEXT_ID_SCREEN, "Screen"))
|
||||
.translation_context(BLT_I18NCONTEXT_ID_SCREEN);
|
||||
}
|
||||
|
||||
static void node_composit_init_keyingscreen(const bContext *C, PointerRNA *ptr)
|
||||
|
||||
Reference in New Issue
Block a user