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.
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").
Here are some code examples:
m_newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
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->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
// 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);
QString languageName = QLocale::languageToString(locale.language());
if(0 != m_errorModel)
m_errorModel->addInfo(tr("Current Language changed to %1").arg(languageName));
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);
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".
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.
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".
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.