Fix: UI: File execute operator button text is not localized #110776

Closed
Colin Basnett wants to merge 1 commits from cmbasnett/bdk-blender:localize-file-execute-button into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

The operator "execute" button was not having it's text localized because it was just passing it a raw string and not running it through the _IFACE macro. This fixes the issue so that the button is always correctly localized.

Before:
image

After:
image

The operator "execute" button was not having it's text localized because it was just passing it a raw string and not running it through the `_IFACE` macro. This fixes the issue so that the button is always correctly localized. Before: ![image](/attachments/9fa81c33-3010-43de-ae43-6096af777953) After: ![image](/attachments/055bd2a9-c4ac-49d1-960b-eca05c7a0294)
Colin Basnett added the
Module
User Interface
Interest
Translations
labels 2023-08-04 01:30:33 +02:00
Colin Basnett self-assigned this 2023-08-04 01:30:33 +02:00
Colin Basnett added 1 commit 2023-08-04 01:30:45 +02:00
Hans Goudey changed title from UI: Fix bug where the file execute operator button text is not being localized to Fix: UI: File execute operator button text is not localized 2023-08-04 01:34:46 +02:00
Colin Basnett requested review from Bastien Montagne 2023-08-09 00:53:57 +02:00
Bastien Montagne requested changes 2023-08-09 11:13:04 +02:00
Bastien Montagne left a comment
Owner

Ah, nice catch. However I believe the translation should happen in WM_operatortype_name.

The call to RNA_struct_ui_name there already does contextual translation, but the call to potential ot->get_name does not. So the last line of that function should be something like:

return (name && name[0]) ? CTX_IFACE_(RNA_struct_translation_context(ot->srna), name) : RNA_struct_ui_name(ot->srna);

Ah, nice catch. However I believe the translation should happen in `WM_operatortype_name`. The call to `RNA_struct_ui_name` there already does contextual translation, but the call to potential `ot->get_name` does not. So the last line of that function should be something like: ` return (name && name[0]) ? CTX_IFACE_(RNA_struct_translation_context(ot->srna), name) : RNA_struct_ui_name(ot->srna);`
Author
Member

Ah, nice catch. However I believe the translation should happen in WM_operatortype_name.

The call to RNA_struct_ui_name there already does contextual translation, but the call to potential ot->get_name does not. So the last line of that function should be something like:

return (name && name[0]) ? CTX_IFACE_(RNA_struct_translation_context(ot->srna), name) : RNA_struct_ui_name(ot->srna);

In my case, ot->get_name is null for my operator, so this might actually be a separate issue entirely.

This translation fails if the "Operator" context is passed through to the underlying lookup functions. The Japanese translation has a contextless translation for "Import" (インポト) that is used elsewhere such as the File -> Import menu, but not one for the "Operator" context.

I'm not too familiar with how the system is supposed to work, but I was under the impression that it might fall back to a contextless translation if no translation exists for the given context. So perhaps this is just a case of missing context translations for "Import" in Japanese specifically. I see that an "Operator" context translation exists for "Export", but not for "Import".

> Ah, nice catch. However I believe the translation should happen in `WM_operatortype_name`. > > The call to `RNA_struct_ui_name` there already does contextual translation, but the call to potential `ot->get_name` does not. So the last line of that function should be something like: > > ` return (name && name[0]) ? CTX_IFACE_(RNA_struct_translation_context(ot->srna), name) : RNA_struct_ui_name(ot->srna);` > In my case, `ot->get_name` is null for my operator, so this might actually be a separate issue entirely. This translation fails if the "Operator" context is passed through to the underlying lookup functions. The Japanese translation has a contextless translation for "Import" (インポト) that is used elsewhere such as the File -> Import menu, but not one for the "Operator" context. I'm not too familiar with how the system is supposed to work, but I was under the impression that it might fall back to a contextless translation if no translation exists for the given context. So perhaps this is just a case of missing context translations for "Import" in Japanese specifically. I see that an "Operator" context translation exists for "Export", but not for "Import".

Well yes, indeed there seems to be nowhere where "Import" is defined as UI label with the Operator context. "Export" happens to be through the 3D print utils add-on.

Using the Operator context here is the expected thing, so if you want your own add-on to be translated, you'll have to handle it yourself (see https://wiki.blender.org/wiki/Source/Interface/Internationalization#Python_Translation_API and https://wiki.blender.org/wiki/Process/Translate_Blender#Translating_non-official_addons).

Will handle to fix with ot->get_name case myself then, closing this PR since it's not actually addressing any issue in Blender.

Well yes, indeed there seems to be nowhere where `"Import"` is defined as UI label with the `Operator` context. `"Export"` happens to be through the 3D print utils add-on. Using the `Operator` context here is the expected thing, so if you want your own add-on to be translated, you'll have to handle it yourself (see https://wiki.blender.org/wiki/Source/Interface/Internationalization#Python_Translation_API and https://wiki.blender.org/wiki/Process/Translate_Blender#Translating_non-official_addons). Will handle to fix with `ot->get_name` case myself then, closing this PR since it's not actually addressing any issue in Blender.
Bastien Montagne closed this pull request 2023-08-11 11:13:07 +02:00
Member

I was under the impression that it might fall back to a contextless translation if no translation exists for the given context.

This is not the case, because contexts allow for disambiguation between multiple translations of a given message. If a translation falls back to an unrelated context it may result in a nonsensical message being displayed. It’s better instead to just display the untranslated one, which at least signals developers that a translation is missing.

Where is this "Import" message coming from? Is it a custom importer add-on? Because AFAICT all official importers have their buttons properly translated, whether from C++ or Python. If it is a custom Python importer, you need to register translations yourself. The translation tuple can be generated using the Manage UI Translations add-on.

EDIT: Whoops should have refreshed the page!

> I was under the impression that it might fall back to a contextless translation if no translation exists for the given context. This is not the case, because contexts allow for disambiguation between multiple translations of a given message. If a translation falls back to an unrelated context it may result in a nonsensical message being displayed. It’s better instead to just display the untranslated one, which at least signals developers that a translation is missing. Where is this "Import" message coming from? Is it a custom importer add-on? Because AFAICT all official importers have their buttons properly translated, whether from C++ or Python. If it is a custom Python importer, you need to [register translations](https://docs.blender.org/api/current/bpy.app.translations.html) yourself. The translation tuple can be generated using the [Manage UI Translations](https://wiki.blender.org/wiki/Process/Translate_Blender#Translating_non-official_addons) add-on. EDIT: Whoops should have refreshed the page!

Pull request closed

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
3 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#110776
No description provided.