I18n: add per-socket translation contexts for nodes #105195

Merged
Hans Goudey merged 3 commits from pioverfour/blender:dp_per_node_socket_translation_context into main 2023-03-06 14:24:49 +01:00
Member

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.


This is a new approach for D15869. Since then, node systems have been ported to the C++ node declaration system.

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. ----- This is a new approach for [D15869](https://archive.blender.org/developer/D15869). Since then, node systems have been ported to the C++ node declaration system.
Damien Picard reviewed 2023-02-25 01:59:32 +01:00
@ -184,0 +187,4 @@
const nodes::SocketDeclaration &socket_decl = *socket.runtime->declaration;
/* The node is not explicitly defined. */
if (&socket_decl == nullptr) {
Author
Member

This is needed to avoid a crash when certain nodes are added (for instance, Render Layers in the compositing nodes).

GCC gives a warning:
the compiler can assume that the address of ‘socket_decl’ will never be NULL [-Waddress].

I suppose it means this should not happen because a null pointer would mean a bug occurs before reaching this point. But I don’t know how to fix this better since it appears not all nodes have a declaration.

This is needed to avoid a crash when certain nodes are added (for instance, Render Layers in the compositing nodes). GCC gives a warning: `the compiler can assume that the address of ‘socket_decl’ will never be NULL [-Waddress]`. I suppose it means this should not happen because a null pointer would mean a bug occurs before reaching this point. But I don’t know how to fix this better since it appears not all nodes have a declaration.

You cannot use a reference if there is a chance that the pointer will be NULL. So if socket.runtime->declaration can be nullptr, you need to use a pointer for socket_decl - or do the check before assigning it to your reference.

You cannot use a reference if there is a chance that the pointer will be NULL. So if `socket.runtime->declaration` can be `nullptr`, you need to use a pointer for `socket_decl` - or do the check before assigning it to your reference.

At first check socket.runtime->declaration != nullptr, and after that dereference pointer

At first check `socket.runtime->declaration != nullptr`, and after that dereference pointer
Author
Member

Thanks for the help! I hope I fixed this correctly.

Thanks for the help! I hope I fixed this correctly.
Damien Picard requested review from Bastien Montagne 2023-02-25 02:00:17 +01:00
Damien Picard requested review from Hans Goudey 2023-02-25 02:00:18 +01:00

@blender-bot build

@blender-bot build
Bastien Montagne requested changes 2023-02-27 15:17:40 +01:00
Bastien Montagne left a comment
Owner

Generally LGTM, though there are a few points to be addressed as noted below.

Would also summon @JacquesLucke here. ;)

Generally LGTM, though there are a few points to be addressed as noted below. Would also summon @JacquesLucke here. ;)
@ -184,0 +198,4 @@
}
output << translation_context.data();
return BLI_strdup(output.str().c_str());

Not sure why you are using an intermediate std::stringstream here? Can't you just do return BLI_strdup(socket_decl.translation_context.c_str()); ?

Not sure why you are using an intermediate `std::stringstream` here? Can't you just do `return BLI_strdup(socket_decl.translation_context.c_str());` ?
Member

That sounds reasonable.
I guess the reason for why the std::stringstream was used is that you assigned it to a StringRef which does not have c_str method, because it might not be null-terminated. Using const StringRefNull or what @mont29 would be better though.

That sounds reasonable. I guess the reason for why the `std::stringstream` was used is that you assigned it to a `StringRef` which does not have `c_str` method, because it might not be null-terminated. Using `const StringRefNull` or what @mont29 would be better though.
Author
Member

To be quite honest I copied code doing a similar thing from node_socket_get_tooltip(), but I see that it doesn’t really apply here.
I’ll go with @mont29 ’s solution.

To be quite honest I copied code doing a similar thing from `node_socket_get_tooltip()`, but I see that it doesn’t really apply here. I’ll go with @mont29 ’s solution.
pioverfour marked this conversation as resolved
Bastien Montagne requested review from Jacques Lucke 2023-02-27 15:18:01 +01:00
Jacques Lucke approved these changes 2023-02-27 15:56:37 +01:00
Jacques Lucke left a comment
Member

Besides what was mentioned in the code comments, this looks good to me.

Besides what was mentioned in the code comments, this looks good to me.
Damien Picard force-pushed dp_per_node_socket_translation_context from 04b5877712 to 8e79420a20 2023-02-27 16:18:27 +01:00 Compare
Author
Member

@JacquesLucke @mont29 Do you reckon this can go into 3.5?

@JacquesLucke @mont29 Do you reckon this can go into 3.5?
Hans Goudey requested changes 2023-02-28 05:33:18 +01:00
Hans Goudey left a comment
Member

Noticed one issue, big picture seems good.

Noticed one issue, big picture seems good.
@ -184,0 +195,4 @@
return nullptr;
}
return BLI_strdup(translation_context.data());
Member

Why BLI_strdup? Could you just use StringRefNull and return that directly? It looks like the result isn't being freed, and this negates the benefit of any small string optimization in std::string

Why `BLI_strdup`? Could you just use `StringRefNull` and return that directly? It looks like the result isn't being freed, and this negates the benefit of any small string optimization in `std::string`
pioverfour marked this conversation as resolved
Bastien Montagne approved these changes 2023-02-28 09:29:11 +01:00
Bastien Montagne left a comment
Owner

Besides point raised by @HooglyBoogly, LGTM. But don't think this should go in 3.5, it's not that trivial of a change...

Besides point raised by @HooglyBoogly, LGTM. But don't think this should go in 3.5, it's not that trivial of a change...
Damien Picard added 1 commit 2023-02-28 19:56:05 +01:00
Use a `StringRefNull` to store the translation context instead of
passing it through `BLI_strdup()`.
Hans Goudey approved these changes 2023-02-28 20:02:23 +01:00
Hans Goudey merged commit 4dc59c7311 into main 2023-03-06 14:24:49 +01:00
Bastien Montagne deleted branch dp_per_node_socket_translation_context 2023-03-06 15:21:17 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105195
No description provided.