I18n: Add translation contexts to properties declared from Python #107150
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#107150
Loading…
Reference in New Issue
No description provided.
Delete Branch "pioverfour/blender:dp_python_props_i18n_context"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Some property labels need a context to disambiguate them from others
which have the same name.
The only way to show the proper text currently for such properties is
to override it in the UI code with a translation context, like:
Python properties already store a translation context though, but this
context cannot be chosen from a Python script.
For instance, typing:
will print
*
, the default context for Python props.This commit allows specifying a context in this manner:
will now print
Amount
and can be translated differently from otherlabels. In this instance, the word for a surface area measurement,
instead of a UI area.
This is what translated properties look like using the existing ("Area", "") and ("Area", "Amount") messages:
The panel can be generated with this script:
python_prop_contexts_test.py
63616087ec
to00fe3e60ae
Feature makes sense to me, and code looks good. Comments below are mainly for style/formatting issues.
@ -2739,6 +2745,7 @@ static int bpy_struct_id_used(StructRNA *srna, char *identifier)
PyDoc_STRVAR(BPy_BoolProperty_doc,
".. function:: BoolProperty(name=\"\", "
"description=\"\", "
"translation_context=\"\", "
Should be
"translation_context=\"*\", "
I think?Same in other docstrings below of course.
@ -2769,2 +2776,3 @@
};
const char *name = NULL, *description = "";
const char *name = NULL, *description = "",
*translation_context = BLT_I18NCONTEXT_DEFAULT_BPYRNA;
avoid wrapping multiple variables declarations over more than one line. Better to keep it on one line, and repeat the type for the next line.
Same for the other similar cases below of course.
@ -3305,3 +3316,1 @@
"get",
"set",
NULL,
"attr", "name", "description", "translation_context",
Please keep existing format ;)
I followed the advice here, and the formatting is from ClangFormat.
Should I still disable automatic formatting and revert the change? If so, should I reformat the entire file in a separate commit so others don’t have to do it?
@ -3438,2 +3455,2 @@
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_NUM_MIN_DOC
" :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC
"\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_CTXT_DOC
BPY_PROPDEF_NUM_MIN_DOC " :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC
broken format, should be on two different lines.
This is coming from ClangFormat as well. Even if I temporarily disable formatting on save, it will still happen as soon as someone formats the codebase. Not sure how to avoid it here…
@blender-bot build
@blender-bot ping
pong
@blender-bot build
Minor request, otherwise LGTM.
NOTE: it would be good to list known translation contexts as part of our API docs, the
translation_context
RNA argument can then point to this too, that seems outside the scope of this patch though.@ -4388,6 +4438,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
.srna = srna,
};
const char *name = NULL, *description = "";
const char *translation_context = BLT_I18NCONTEXT_DEFAULT_BPYRNA;
Set to NULL, there is no need to call
RNA_def_property_translation_context
if it's not set as BLT_I18NCONTEXT_DEFAULT_BPYRNA is already the default. Same for all other cases.@ -18,6 +18,8 @@
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
This is no longer needed.
@ -4482,6 +4536,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
}
prop = RNA_def_collection_runtime(
srna, id_data.value, ptype, name ? name : id_data.value, description);
RNA_def_property_translation_context(prop, translation_context);
These functions don't need to run when the
translation_context
is NULL.@blender-bot build