I18n: Remove extraction macros from the node socket declarations #107258

Merged
Bastien Montagne merged 3 commits from pioverfour/blender:dp_geo_nodes_remove_extraction_macros into main 2023-05-16 14:13:01 +02:00
Member

The node socket declaration uses the N_() macro to extract the name
and description of the socket.

This is quite redundant because since the syntax is always the same,
the extraction can be done automatically from the Python translation
module using regexes.

Four new regexes are introduced in bl_i18n_utils.settings:

  • one extracts contextless messages from add_input() and
    add_output(), the basic socket declarations with the names;
  • one does the same, but for those sockets which declare a context
    through .translation_context();
  • one extracts descriptions and error messages;
  • one extracts geometry nodes field inputs.

In addition to making the code simpler and more legible, this change
extracts a few dozen messages which were not tagged with the proper
macro.

The node socket declaration uses the `N_()` macro to extract the name and description of the socket. This is quite redundant because since the syntax is always the same, the extraction can be done automatically from the Python translation module using regexes. Four new regexes are introduced in bl_i18n_utils.settings: - one extracts contextless messages from `add_input()` and `add_output()`, the basic socket declarations with the names; - one does the same, but for those sockets which declare a context through `.translation_context()`; - one extracts descriptions and error messages; - one extracts geometry nodes field inputs. In addition to making the code simpler and more legible, this change extracts a few dozen messages which were not tagged with the proper macro.
Damien Picard requested review from Bastien Montagne 2023-04-23 04:01:14 +02:00
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from a3ed424c39 to bc05c95da5 2023-04-23 16:22:40 +02:00 Compare
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from bc05c95da5 to 51040b560f 2023-04-24 21:26:14 +02:00 Compare
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from 51040b560f to 75cacf6663 2023-04-24 22:11:41 +02:00 Compare
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from 75cacf6663 to 4026419109 2023-04-25 15:44:12 +02:00 Compare
Bastien Montagne reviewed 2023-04-28 19:17:34 +02:00
Bastien Montagne left a comment
Owner

While this change may be fine in current status of node code, I have tow concerns:

First, names like add_input are very generic and could easily conflict with future code. Don't really see a good way to address that though.

The second one is more a topic for the #Nodes-&-Physics module, but I find it fairly annoying that such a huge part of Blender is not properly available to introspection through RNA?

While this change may be fine in current status of node code, I have tow concerns: First, names like `add_input` are _very_ generic and could easily conflict with future code. Don't really see a good way to address that though. The second one is more a topic for the #Nodes-&-Physics module, but I find it fairly annoying that such a huge part of Blender is not properly available to introspection through RNA?
@ -257,2 +257,4 @@
for it in ("modifier_subpanel_register", "gpencil_modifier_subpanel_register")) +
# Node socket declarations: contextless names
tuple((r"\.{}<decl::.*?>\(\s*" + _msg_re + r"\s*\)").format(it)

I don't think this will handle properly cases with more than one string passed to the constructor, like in b.add_input<decl::Float>("Value", "Value_001") ?

I don't think this will handle properly cases with more than one string passed to the constructor, like in ` b.add_input<decl::Float>("Value", "Value_001")` ?
Author
Member

I don't think this will handle properly cases with more than one string passed to the constructor, like in b.add_input<decl::Float>("Value", "Value_001") ?

My understanding from this block is that the second string is only an identifier and can always be ignored for translation. Also at present, every instance where add_(in|out)put() is called with two arguments, only the first one has a N_() extraction tag.

> I don't think this will handle properly cases with more than one string passed to the constructor, like in ` b.add_input<decl::Float>("Value", "Value_001")` ? My understanding from [this block](https://projects.blender.org/blender/blender/src/branch/main/source/blender/nodes/NOD_node_declaration.hh#L515-L518) is that the second string is only an identifier and can always be ignored for translation. Also at present, every instance where `add_(in|out)put()` is called with two arguments, only the first one has a `N_()` extraction tag.
Member

Yes, that's right

Yes, that's right

@pioverfour I was not clear enough here, my concern is that the current regex will not match on multi-parameters cases. The r"\s*\)" part of the regex requires zero or more 'space-like' chars and a closing ).

See e.g. how modifier_subpanel_register & co are handled. You probably need to add something like r"(?:,[^),]+)*\s*\)" (or + instead of * if there can ever only be one additional optional parameter) to match & discard any extra parameter...

@pioverfour I was not clear enough here, my concern is that the current regex will not match on multi-parameters cases. The `r"\s*\)"` part of the regex requires zero or more 'space-like' chars and a closing `)`. See e.g. how `modifier_subpanel_register` & co are handled. You probably need to add something like `r"(?:,[^),]+)*\s*\)"` (or `+` instead of `*` if there can ever only be one additional optional parameter) to match & discard any extra parameter...
Author
Member

Ah, yes of course! Thanks.

Ah, yes of course! Thanks.
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from 4026419109 to 085a84f9d9 2023-04-29 00:04:31 +02:00 Compare
Member

but I find it fairly annoying that such a huge part of Blender is not properly available to introspection through RNA?

This is an ongoing pain point for us too, but the transition from the static socket array for nodes to the socket declaration is a large one and we don't want to expose it to RNA while it's still changing. It is on our radar though.

>but I find it fairly annoying that such a huge part of Blender is not properly available to introspection through RNA? This is an ongoing pain point for us too, but the transition from the static socket array for nodes to the socket declaration is a large one and we don't want to expose it to RNA while it's still changing. It is on our radar though.
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from 085a84f9d9 to a0013d616a 2023-05-07 16:48:07 +02:00 Compare
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from a0013d616a to 6c2c5d2feb 2023-05-10 12:02:13 +02:00 Compare
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from 6c2c5d2feb to 5c93654067 2023-05-13 17:53:22 +02:00 Compare
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from 5c93654067 to 04525f8bcb 2023-05-15 18:46:44 +02:00 Compare
Author
Member

While I was rebasing on latest main to resolve conflicts, I noticed that some labels come from the node_sock_label() function. So I added a new commit in between the existing ones, with the new regex:

    # Node socket labels
    tuple((r"{}\(\s*[^,]+,\s*" + _msg_re + r"\s*\)").format(it)
          for it in ("node_sock_label",)) + 
While I was rebasing on latest main to resolve conflicts, I noticed that some labels come from the `node_sock_label()` function. So I added a new commit in between the existing ones, with the new regex: ```python # Node socket labels tuple((r"{}\(\s*[^,]+,\s*" + _msg_re + r"\s*\)").format(it) for it in ("node_sock_label",)) + ```
Bastien Montagne approved these changes 2023-05-15 18:49:14 +02:00

@pioverfour looks like this PR needs to be updated by hands ;)

@pioverfour looks like this PR needs to be updated by hands ;)

Oh, hehe, looks we have been colliding...

Oh, hehe, looks we have been colliding...

Sorry, surprised we could...

Sorry, surprised we could...
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from 04525f8bcb to e149997be1 2023-05-15 18:59:19 +02:00 Compare

@blender-bot build

@blender-bot build
Damien Picard force-pushed dp_geo_nodes_remove_extraction_macros from e149997be1 to 9b313102bb 2023-05-15 22:34:05 +02:00 Compare
Bastien Montagne merged commit 22f641e7f8 into main 2023-05-16 14:13:01 +02:00
Bastien Montagne deleted branch dp_geo_nodes_remove_extraction_macros 2023-05-16 14:13:02 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:39 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
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, Assets & 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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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
4 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#107258
No description provided.