Fix that hotkey file required mixed-language definitions#284
Conversation
The main menus were required in English, but submenus were needed in localized language of the menu label. This made it very difficult to figure out how to make hotkeys work. This patch makes that main menus are also localized, thus the GUI can be used to visually inspect and write in. The patch was developed with help by Claude Code - fully reviewed and tested, except that I cannot get the "Profiles" third level do anything, despite the menu item displays the assigned hotkey. I'll separately submit a Default Hungarian hotkey file.
|
Here is the Claude Code session if necessary, including alternative approaches for later. ❯ I tracked down a bug in this RoxTerm program in this directory, it's an open source terminal. (Now I just try if ● Let me check the memory index and get some context on what you've found. Recalled 1 memory (ctrl+o to expand) ● Bash(git -C /home/lion/tmp/roxterm log --oneline -10 && git -C /home/lion/tmp/roxterm diff master..HEAD --stat) ● The branch fix-hotkeyfile is ahead of master by 0 commits — looks like you haven't committed the fix yet. What's the ✻ Sautéed for 8s ❯ How can I write mutliple lines here? Shift enter seems to submit the prompt. ● In Claude Code, you can write multiple lines using Option+Enter (on Mac) or Alt+Enter (on Linux/Windows) to insert a Alternatively, you can paste multi-line text directly into the prompt. ✻ Worked for 2s ❯ I put a file here called "my-test-hotkeys.txt", this is a copy of the hotkey file RoxTerm currently loads, a standard ● Let me read the relevant code sections before making suggestions. Searched for 5 patterns, read 3 files (ctrl+o to expand) ● Now I have a clear understanding of the mechanism. Let me trace exactly what's happening: How it works:
The inconsistency:
Design options for the file format: Option 1 — All English (recommended for portability) Option 2 — All localized (consistent, simple rule) Option 3 — Symbolic internal IDs (most robust, breaking change) Option 4 — Accept both English and localized (best UX, hardest) Pragmatic recommendation: Option 2 is the smallest, cleanest fix for consistency. Option 1 is better for multi-locale ✻ Crunched for 2m 27s ❯ This feature currently has no GUI (it just opens this file in text editor), so a user with a translated user ● Yes, that reasoning is sound. The two-phase approach makes sense:
One thing worth noting now so it doesn't bite later: if you ever make that switch, existing hand-edited localized So the short-term plan is: fix the section names to use the translated strings (pass _("File") instead of "File" in ✻ Crunched for 15s ❯ Excellent, thanks. Please implement the fix with localized names. ● Let me read the full menutree.c to find the top-level menu item labels and the menutree_labels array. Searched for 1 pattern, read 1 file (ctrl+o to expand) ● Let me check the Tabs menu labels and the menutree header for the full list of IDs. Searched for 1 pattern, read 1 file (ctrl+o to expand) ● Let me read the exact macro definition to confirm Tabs and Search are in TOP_LEVEL_MENU_ITEMS. Searched for 1 pattern, read 1 file (ctrl+o to expand) ● Good — menutree_set_accel_path_for_item is only used inside menutree_apply_shortcuts. I now have everything I need.
● Update(src/menutree.c) ● Update(src/menutree.c) ● Now replace menutree_apply_shortcuts: ● Update(src/menutree.c) ● Now let's verify it compiles: ● Bash(cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug 2>&1 | tail -5 && cmake --build build --target roxterm 2>&1 | grep ● Bash(cmake --build build --target roxterm 2>&1 | tail -5) ● Clean build, no warnings. The changes:
In an English locale the behaviour is identical to before. In a Hungarian (or any other translated) locale, users can ✻ Churned for 7m 17s ❯ /rename roxterm-hotkeys |
|
I don't agree with using option 2 (use the local language in the keyfile). The main problem with it is that the supplied Default file would only work in English. Instead I think we should use option 1 (the keyfile uses untranslated English). The strings can be translated after reading them from the keyfile to match the translated label used by GTK. To make the UX easier, roxterm could regenerate the file just before opening the text editor. It could add all the available menu items to the file, commenting out the ones that aren't bound. When the locale isn't English it could add an additional comment above each one, showing the translated version. |
|
I absolutely agree with your explanation. Thank you for fast feedback! I was also worried about this approach, but this was the smallest change, only 20-25 lines. Getting the original English name of the menu might take a bit more. Please do not close this PR, I'll see if Claude wants to build on this branch or start over from "master". (I think some of these changes are already a good start.) (I think adding more commits to this branch will expand the PR, we will see.) Your ideas are quite good, they fully solve all problems. I'll get back soon with a better solution. |
|
It does make sense for you to continue working with Claude Code, thanks for offering. TBH it's so long since I worked on this that I can't really remember how all this works. You're right, looking up the untranslated names is harder than I realised. I don't know why GTK is translating the accel paths for menu items but not the top-level menus. It shouldn't be translating either, because the accel path strings aren't flagged with () or N(), but perhaps there are matching strings tagged for translation elsewhere. But it doesn't make sense that GTK translates accel paths at all. There is probably a better way to do this, based on GAction, or even with builder XML, but that might need more major refactoring. The reason I didn't do it in a more standard way like that in the first place is probably because it originally started as a GTK 2 app and I took the path of least resistance when upgrading it to GTK 3. Maybe, instead of applying the English strings as accel paths, we could hash them, or use a look-up table, to make sure they are all unique strings that aren't translated. |
The main menus were required in English, but submenus were needed in localized language of the menu label. This made it very difficult to figure out how to make hotkeys work. This patch makes that main menus are also localized, thus the GUI can be used to visually inspect and write in. The patch was developed with help by Claude Code - fully reviewed and tested, except that I cannot get the "Profiles" third level do anything, despite the menu item displays the assigned hotkey. I'll separately submit a Default Hungarian hotkey file.