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. Translate "Ctrl"
Forum Updated to NodeBB v4.3 + New Features

Translate "Ctrl"

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.9k Views 1 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.
  • W Offline
    W Offline
    Wurstinator
    wrote on last edited by
    #1

    Hello,
    when using shortcuts for QActions in a QMenu, that shortcut is shown next to the QAction's text (New Ctrl+N).
    What I am having a problem with, is, as this topic's title indicates, translating this shortcut. In German, for example, it would be Strg+N instead of Ctrl+N. I tried multiple suggestions from Google already, for example add the translation of "Ctrl" into my .ts file, of which none actually helped.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      it depends on how you create the actions.
      If you use the QKeySequence stuff, you have to load the qt translations, then it works.
      If you set the shortcuts by using the string style, use tr("Ctrl+N").

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        Here are some code examples:

        @
        m_newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
        m_newAct->setShortcuts(QKeySequence::New);
        m_newAct->setStatusTip(tr("Create a new file"));
        connect(m_newAct, SIGNAL(triggered()), this, SLOT(newFile()));
        @

        or using the tr - style:

        @
        m_uploadAct = new QAction(QIcon(":/images/upload.png"), tr("&Upload"), this);
        m_uploadAct->setShortcuts(tr("Ctrl+B"));
        m_uploadAct->setStatusTip(tr("Upload all data from the client to the server while deleting the data on the server."));
        connect(m_uploadAct, SIGNAL(triggered()), SLOT(upload()));
        @

        For installing the Qt translations, you have to put them somewhere beside your delkivered code and do:

        @
        void switchTranslator(QTranslator& translator, const QString& filename)
        {
        // remove the old translator
        qApp->removeTranslator(&translator);

        // load the new translator
        if(translator.load(filename))
            qApp->installTranslator(&translator);
        

        }

        void GMainWindow::loadLanguage(const QString& rszLanguage)
        {
        if(m_szCurrentLanguage != rszLanguage)
        {
        m_szCurrentLanguage = rszLanguage;
        QLocale locale = QLocale(m_szCurrentLanguage);
        QLocale::setDefault(locale);
        QString languageName = QLocale::languageToString(locale.language());
        switchTranslator(m_translator, QString("%1/ArticleManagement_%2.qm")
        .arg(m_szLanguagePath).arg(rszLanguage));
        switchTranslator(m_translatorQt, QString("%1/qt_%2.qm")
        .arg(m_szLanguagePath).arg(rszLanguage));
        if(0 != m_errorModel)
        m_errorModel->addInfo(tr("Current Language changed to %1").arg(languageName));
        }
        }
        @

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Wurstinator
          wrote on last edited by
          #4

          My code is not as detailed as yours but I guess that should not matter because the translation file is loaded correctly anyway.
          @QTranslator *transl = new QTranslator;
          transl->load(QLocale::system(), "text adventure maker", "_", QApplication::applicationDirPath());
          QApplication a(argc, argv);
          a.installTranslator(transl);@
          However, it's still "Ctrl".

          I am using QKeySequence, by the way. I tried the string method but Qt reduces my "Strg+N" to simply "N".

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            Hi Wurstinator,

            If you read my code, you saw, I loaded two translation files, my private one and one from Qt: qt_de.qm. The translations for the KeyEvents is done there, it does not help if you just add Ctrl in your translation.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Wurstinator
              wrote on last edited by
              #6

              Thanks, that did the trick. I never heard of this file before so I did not understand what you meant with "you have to load the qt translations".

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                These files are needed for all Qt UI things you use, e.g. for standard dialogs that are not native (message box) or QInputDialog. Also for KeySequences etc.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                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