Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to deal with "&" for shortcuts in translatable strings?
Forum Updated to NodeBB v4.3 + New Features

How to deal with "&" for shortcuts in translatable strings?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 354 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    buhtz
    wrote on last edited by
    #1

    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 from O to Ö.

    Another example is _('&General').
    Translated into Russian: '&Общие' result in an O shortcut which maybe override another O shortcut.

    How do you control things like this in your applications? Should I avoid using the & in such strings?

    Gojir4G 1 Reply Last reply
    0
    • B buhtz

      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 from O to Ö.

      Another example is _('&General').
      Translated into Russian: '&Общие' result in an O shortcut which maybe override another O shortcut.

      How do you control things like this in your applications? Should I avoid using the & in such strings?

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @buhtz IMHO it's up to the translator to handle this and ensure there is not any duplicates in shortcut. If you have twice O shortcuts, you have to change one of them for using another letter, there is not magic behind for doing it for you.

      JonBJ 1 Reply Last reply
      1
      • Gojir4G Gojir4

        @buhtz IMHO it's up to the translator to handle this and ensure there is not any duplicates in shortcut. If you have twice O shortcuts, you have to change one of them for using another letter, there is not magic behind for doing it for you.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @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.)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on last edited by
          #4

          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 as QKeySequence::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.

          B 1 Reply Last reply
          0
          • S SimonSchroeder

            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 as QKeySequence::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.

            B Offline
            B Offline
            buhtz
            wrote on last edited by
            #5

            Thanks for all your input and ideas.

            I realized that it isn't that easy to remove all & and use setShortcut() instead. For example the main menubar do underline the shortcut letters in there labels. But it does not when removing the & and using setShortcuts(). 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.

            S 1 Reply Last reply
            0
            • B buhtz

              Thanks for all your input and ideas.

              I realized that it isn't that easy to remove all & and use setShortcut() instead. For example the main menubar do underline the shortcut letters in there labels. But it does not when removing the & and using setShortcuts(). 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.

              S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #6

              @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. Pressing Alt will open the menu and then letters can be used for quick navigation. (Real) shortcuts as set by setShortcut() are different. For these you don't have to navigate through menus at all. Usually, these use the Ctrl key and not the Alt key, like Ctrl + 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 (take Ctrl + 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 the Ctrl key. Especially for apps that are not text editors, e.g. Photoshop, there are a lot of single letter shortcuts without hitting the Ctrl key first.)

              B 1 Reply Last reply
              0
              • S SimonSchroeder

                @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. Pressing Alt will open the menu and then letters can be used for quick navigation. (Real) shortcuts as set by setShortcut() are different. For these you don't have to navigate through menus at all. Usually, these use the Ctrl key and not the Alt key, like Ctrl + 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 (take Ctrl + 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 the Ctrl key. Especially for apps that are not text editors, e.g. Photoshop, there are a lot of single letter shortcuts without hitting the Ctrl key first.)

                B Offline
                B Offline
                buhtz
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved