WIP: I18n: add per-label translation contexts for nodes #105690

Draft
Damien Picard wants to merge 3 commits from pioverfour/blender:dp_add_i18n_context_socket_label into blender-v3.6-release

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 18 additions and 2 deletions
Showing only changes of commit 538d053eed - Show all commits

View File

@ -201,6 +201,7 @@ class bNodeSocketRuntime : NonCopyable, NonMovable {
int index_in_node = -1;
int index_in_all_sockets = -1;
int index_in_inout_sockets = -1;
std::string label_translation_context;
};
/**

View File

@ -191,6 +191,11 @@ namespace blender::ed::space_node {
static const char *node_socket_get_translation_context(const bNodeSocket &socket)
{
/* Get the context from the label if it is defined. */
if (socket.runtime->label_translation_context[0] != '\0') {
return socket.runtime->label_translation_context.c_str();
}
/* The node is not explicitly defined. */
if (socket.runtime->declaration == nullptr) {
return nullptr;

View File

@ -73,9 +73,12 @@ void *node_initexec_curves(bNodeExecContext * /*context*/, bNode *node, bNodeIns
/** \name Updates
* \{ */
void node_sock_label(bNodeSocket *sock, const char *name)
void node_sock_label(bNodeSocket *sock, const char *name, const char *translation_context)
{
STRNCPY(sock->label, name);
if (translation_context) {
sock->runtime->label_translation_context = translation_context;
}
}
void node_sock_label_clear(bNodeSocket *sock)
@ -83,6 +86,9 @@ void node_sock_label_clear(bNodeSocket *sock)
if (sock->label[0] != '\0') {
sock->label[0] = '\0';
}
if (sock->runtime->label_translation_context[0] != '\0') {
sock->runtime->label_translation_context[0] = '\0';
}
}
void node_math_update(bNodeTree *ntree, bNode *node)

View File

@ -7,6 +7,8 @@
#pragma once
#include "BLT_translation.h"
struct bNode;
struct bNodeTree;
@ -30,7 +32,9 @@ void node_copy_standard_storage(bNodeTree *dest_ntree, bNode *dest_node, const b
void *node_initexec_curves(bNodeExecContext *context, bNode *node, bNodeInstanceKey key);
pioverfour marked this conversation as resolved Outdated

Would rather have default value be BLT_I18NCONTEXT_DEFAULT (aka nullptr). Also means node_sock_label code changes need an update.

Would rather have default value be `BLT_I18NCONTEXT_DEFAULT` (aka `nullptr`). Also means `node_sock_label` code changes need an update.
/**** Updates ****/
void node_sock_label(bNodeSocket *sock, const char *name);
void node_sock_label(bNodeSocket *sock,
const char *name,
const char *translation_context = BLT_I18NCONTEXT_DEFAULT);
void node_sock_label_clear(bNodeSocket *sock);
void node_math_update(bNodeTree *ntree, bNode *node);