Fix #105548: I18n: many keymap sections cannot be translated #116299

Closed
Damien Picard wants to merge 1 commits from pioverfour:dp_fix_105548 into main

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

In the keymap user preferences, shortcuts are grouped according to a
hierarchy of topics. Some of them cannot be translated, as they do not
get extracted by the i18n script. The issue happens in
walk_keymap_hierarchy(). If the item in the hierarchy is not a
string, it is skipped. This happens for tools defining their own
keymap, because they use a function instead of a string as the name.

In turn, the issue is in keymap_hierarchy.generate(). If run in the
interface, the hierarchy will contain only strings as topic names.
However, if run in the background, some of them will still be
functions, because they are not initialized.

This commit makes keyconfig initialization run in the background as
well.


I’m not entirely sure this is the proper fix. WM_check() is called when a file is opened or when a new window is created, but I’m not sure why the keyconfig init must be run at that point and not on startup. The current fix is simply to move WM_keyconfig_init() outside of the background check but maybe it should be moved somewhere else entirely?

In the keymap user preferences, shortcuts are grouped according to a hierarchy of topics. Some of them cannot be translated, as they do not get extracted by the i18n script. The issue happens in `walk_keymap_hierarchy()`. If the item in the hierarchy is not a string, it is skipped. This happens for tools defining their own keymap, because they use a function instead of a string as the name. In turn, the issue is in `keymap_hierarchy.generate()`. If run in the interface, the hierarchy will contain only strings as topic names. However, if run in the background, some of them will still be functions, because they are not initialized. This commit makes keyconfig initialization run in the background as well. ----- I’m not entirely sure this is the proper fix. `WM_check()` is called when a file is opened or when a new window is created, but I’m not sure why the keyconfig init must be run at that point and not on startup. The current fix is simply to move `WM_keyconfig_init()` outside of the background check but maybe it should be moved somewhere else entirely?
Damien Picard added 1 commit 2023-12-18 13:47:04 +01:00
832208f857 Fix #105548: I18n: many keymap sections cannot be translated
In the keymap user preferences, shortcuts are grouped according to a
hierarchy of topics. Some of them cannot be translated, as they do not
get extracted by the i18n script. The issue happens in
`walk_keymap_hierarchy()`. If the item in the hierarchy is not a
string, it is skipped. This happens for tools defining their own
keymap, because they use a function instead of a string as the name.

In turn, the issue is in `keymap_hierarchy.generate()`. If run in the
interface, the hierarchy will contain only strings as topic names.
However, if run in the background, some of them will still be
functions, because they are not initialized.

This commit makes keyconfig initialization run in the background as
well.
Damien Picard added the
Module
User Interface
Interest
Translations
labels 2023-12-18 13:47:26 +01:00
Damien Picard requested review from Bastien Montagne 2023-12-18 13:47:37 +01:00
Bastien Montagne reviewed 2023-12-19 12:03:03 +01:00
Bastien Montagne left a comment
Owner

This seems to make sense to me, but would also get @ideasman42 review here.


From my understanding, WM_keyconfig_init get called first as part of the WM_init process, but indeed needs to be called again once the startup file is read, which happens through the WM_check call. Im current code, that second call would be skipped in background case.

Not entirely sure though if call should be dependent on the WM_INIT_FLAG_KEYCONFIG flag here? Would rather keep the existing behavior for non-background case (i.e. check on WM_INIT_FLAG_WINDOW). And also because WM_keyconfig_init does some work, even if WM_INIT_FLAG_KEYCONFIG is set.

This seems to make sense to me, but would also get @ideasman42 review here. -------------------- From my understanding, `WM_keyconfig_init` get called first as part of the `WM_init` process, but indeed needs to be called again once the startup file is read, which happens through the `WM_check` call. Im current code, that second call would be skipped in background case. Not entirely sure though if call should be dependent on the `WM_INIT_FLAG_KEYCONFIG` flag here? Would rather keep the existing behavior for non-background case (i.e. check on `WM_INIT_FLAG_WINDOW`). And also because `WM_keyconfig_init` does some work, even if `WM_INIT_FLAG_KEYCONFIG` is set.
Bastien Montagne requested review from Campbell Barton 2023-12-19 12:03:14 +01:00

While this fix seems reasonable, it changes the assumption that key-maps wont exist on startup in background mode (for add-on registration for e.g.). many add-ons have something like this:

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = kc.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new('wm.call_menu', 'SPACE', 'PRESS')
        kmi.properties.name = "VIEW3D_MT_Space_Dynamic_Menu"

It turns out this assumption has already been unintentionally violated - as part of other changes, this PR goes further to ensure the keyconfigs are initialized in background mode.


So I'd rather resolve this in a more isolated change, preparing an alternative fix.

While this fix seems reasonable, it changes the assumption that key-maps wont exist on startup in background mode (for add-on registration for e.g.). many add-ons have something like this: ``` wm = bpy.context.window_manager kc = wm.keyconfigs.addon if kc: km = kc.keymaps.new(name='3D View', space_type='VIEW_3D') kmi = km.keymap_items.new('wm.call_menu', 'SPACE', 'PRESS') kmi.properties.name = "VIEW3D_MT_Space_Dynamic_Menu" ``` It turns out this assumption has *already* been unintentionally violated - as part of other changes, this PR goes further to ensure the keyconfigs are initialized in background mode. ---- So I'd rather resolve this in a more isolated change, preparing an alternative fix.
Author
Member

I see, I wasn’t even aware of this assumption. Thanks for looking into it!

I see, I wasn’t even aware of this assumption. Thanks for looking into it!

Committed alternative fix c59b9ff9c2.

Committed alternative fix c59b9ff9c245ce3c973616446d6a6629109f2dd8.
Campbell Barton closed this pull request 2023-12-20 01:56:10 +01:00
Damien Picard deleted branch dp_fix_105548 2023-12-20 02:05:46 +01:00

Pull request closed

Sign in to join this conversation.
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#116299
No description provided.