How to deal with "&" for shortcuts in translatable strings?
-
I do use GNU gettext to translate strings in my QUI.
I do have menu entries like this:_('&Open')
In German this would be translated into
'&Öffnen
and also change the shortcut fromO
toÖ
.Another example is
_('&General')
.
Translated into Russian:'&Общие'
result in anO
shortcut which maybe override anotherO
shortcut.How do you control things like this in your applications? Should I avoid using the
&
in such strings? -
-
@Gojir4
Which, for the record, seems to me basically to make shortcuts on translation strings too "dangerous" to use, if you care about shortcut uniqueness. You have no idea when some language translation might cause duplicate, and I don't think you have exact context for every string translated to deal with it. (Not that I use translation, but just an observation which has struck me before.) -
Well, the menu entries are not global shortcuts. They only apply in their local context. This is not comparable to
Ctrl + O
(which would better be written asQKeySequence::Open
).I also believe that usually umlauts are avoided, so the translation for
&Open
would most likely be something likeÖ&ffnen
. It is not mandatory to use the first letter for the shortcut. At least on Windows you can have multiple entries with the some shortcut letter. In this case you have to press the letter several times to switch between the options and explicitly confirm the selection (is it space or enter?). The best thing you can do is to add a comment for the translator which will show up inside Linguist. Maybe also add a disambiguation string with the name of the parent menu, e.g. "file-menu" in order to have the shortcut only in this context.We use QActions that are plugged into the QMenu. For these we specify the status tip, tool tip, and icon text as well.
-
Thanks for all your input and ideas.
I realized that it isn't that easy to remove all
&
and usesetShortcut()
instead. For example the main menubar do underline the shortcut letters in there labels. But it does not when removing the&
and usingsetShortcuts()
. The shortcut also do not work by its own. I have to do more work to make the submenu popup when hitting that shortcut.In the end to much work to do just for such a simple issue.
I think I'll keep it up to the translators how to deal with the
&
sign. -
@buhtz said in How to deal with "&" for shortcuts in translatable strings?:
I realized that it isn't that easy to remove all & and use setShortcut() instead.
These are two entirely different things. The
&
is for navigating menus (and dialogs) without the mouse. PressingAlt
will open the menu and then letters can be used for quick navigation. (Real) shortcuts as set bysetShortcut()
are different. For these you don't have to navigate through menus at all. Usually, these use theCtrl
key and not theAlt
key, likeCtrl + S
for saving,Ctrl + P
for printing, etc. These also don't have anything to do with the letter that is underlined inside the menu (takeCtrl + Z
, for example; there is no 'Z' in "Undo"). It is good style to have menu entries with underlined letters for quick keyboard navigation. And if you are able use real shortcuts at least for the most common commands. (Just for completeness sake: Not all (real) shortcuts use theCtrl
key. Especially for apps that are not text editors, e.g. Photoshop, there are a lot of single letter shortcuts without hitting theCtrl
key first.) -
Thanks for your feedback.
I think I will add this men labels with & in it to the translation glossary (using Weblate) and add comments to it for the translators. Not all of them know what an & does.