I18n: add label declaration to node sockets so they can be shortened

In !112591, nodes got the ability to group sockets into panels. The
labels for these sockets are automatically shortened if they begin
with the same text as their parent labels. For instance, "Transmission
Weight" will be shortened to just "Weight" because it is under the
"Transmission" panel.

While this is a good heuristic for English, it breaks down in
languages which do not have the same word order.

This commit adds a `.short_label()` callback to socket declarations so
that a shortened label can be explicitly declared.

It also adds two regexps to the translation script so that these new
fields can be extracted to the .po translation files. One extracts the
label with a translation context, the other without. Only the one
without context is currently in use.

The current automatic shortening logic is kept and will be used only
if a shortened label is not manually provided.

Fixes #112970: Node socket labels under panels are not shortened when
translated.

Pull Request: https://projects.blender.org/blender/blender/pulls/113070
This commit is contained in:
Damien Picard
2023-10-12 17:51:37 +02:00
committed by Bastien Montagne
parent 1a648f5b22
commit 2d703e9200
7 changed files with 81 additions and 8 deletions
+11 -1
View File
@@ -273,7 +273,17 @@ PYGETTEXT_KEYWORDS = (() +
tuple((r"\.{}\(\s*" + _msg_re + r"\s*\)").format(it)
for it in ("description", "error_message_add")) +
# Node socket labels
# Node socket labels from declarations: context-less names
tuple((r"\.{}\(\s*" + _msg_re +
r"\s*\)(?![^;]*\.translation_context\()[^;]*;").format(it)
for it in ("short_label",)) +
# Node socket labels from declarations: names with contexts
tuple((r"\.{}\(\s*" + _msg_re + r"[^;]*\.translation_context\(\s*" +
_ctxt_re + r"\s*\)").format(it)
for it in ("short_label",)) +
# Dynamic node socket labels
tuple((r"{}\(\s*[^,]+,\s*" + _msg_re + r"\s*\)").format(it)
for it in ("node_sock_label",)) +