I18n: Add translation contexts to node panels
Node UIs can now have panels. Some of those may need to have their labels translated using translation contexts. PanelDeclarations already had a translation_context member, this commit adds a way to specify this context, and to use it for translation on drawing the node. Pull Request: https://projects.blender.org/blender/blender/pulls/139124
This commit is contained in:
committed by
Bastien Montagne
parent
8119e4baa7
commit
9ce0a2d1d5
@@ -107,7 +107,11 @@ static void draw_node_inputs_recursive(bContext *C,
|
||||
PanelLayout panel = layout->panel(C, panel_idname, panel_decl.default_collapsed);
|
||||
const bool has_used_inputs = panel_has_input_affecting_node_output(node, panel_decl);
|
||||
uiLayoutSetActive(panel.header, has_used_inputs);
|
||||
panel.header->label(IFACE_(panel_decl.name), ICON_NONE);
|
||||
|
||||
const char *panel_translation_context = (panel_decl.translation_context.has_value() ?
|
||||
panel_decl.translation_context->c_str() :
|
||||
nullptr);
|
||||
panel.header->label(CTX_IFACE_(panel_translation_context, panel_decl.name), ICON_NONE);
|
||||
if (!panel.body) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2633,11 +2633,14 @@ static void node_draw_panels(bNodeTree &ntree, const bNode &node, uiBlock &block
|
||||
}
|
||||
|
||||
/* Panel label. */
|
||||
const char *panel_translation_context = (panel_decl.translation_context.has_value() ?
|
||||
panel_decl.translation_context->c_str() :
|
||||
nullptr);
|
||||
uiBut *label_but = uiDefBut(
|
||||
&block,
|
||||
UI_BTYPE_LABEL,
|
||||
0,
|
||||
IFACE_(panel_decl.name),
|
||||
CTX_IFACE_(panel_translation_context, panel_decl.name),
|
||||
offsetx,
|
||||
int(*panel_runtime.header_center_y - NODE_DYS),
|
||||
short(draw_bounds.xmax - draw_bounds.xmin - (30.0f * UI_SCALE_FAC)),
|
||||
|
||||
@@ -535,6 +535,7 @@ class PanelDeclarationBuilder : public DeclarationListBuilder {
|
||||
}
|
||||
|
||||
Self &description(std::string value = "");
|
||||
Self &translation_context(std::optional<std::string> value = std::nullopt);
|
||||
Self &default_closed(bool closed);
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ static void cmp_node_keying_declare(NodeDeclarationBuilder &b)
|
||||
"luminance intact using a Gaussian blur of the given size")
|
||||
.compositor_expects_single_value();
|
||||
|
||||
PanelDeclarationBuilder &key_panel = b.add_panel("Key").default_closed(true);
|
||||
PanelDeclarationBuilder &key_panel = b.add_panel("Key").default_closed(true).translation_context(
|
||||
BLT_I18NCONTEXT_ID_NODETREE);
|
||||
key_panel.add_input<decl::Float>("Balance", "Key Balance")
|
||||
.default_value(0.5f)
|
||||
.subtype(PROP_FACTOR)
|
||||
|
||||
@@ -867,6 +867,13 @@ PanelDeclarationBuilder &PanelDeclarationBuilder::description(std::string value)
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanelDeclarationBuilder &PanelDeclarationBuilder::translation_context(
|
||||
std::optional<std::string> value)
|
||||
{
|
||||
decl_->translation_context = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PanelDeclarationBuilder &PanelDeclarationBuilder::default_closed(bool closed)
|
||||
{
|
||||
decl_->default_collapsed = closed;
|
||||
|
||||
Reference in New Issue
Block a user