How can I translate the OK and Cancel buttons when using the static QMessageBox functions?
Answer:
The OK and Cancel text for the buttons is part of the Qt source code. If you would like to translate them, then you need to copy the qt_untranslated.ts file which is located under QTDIR/translations. This file contains all of the strings in Qt, untranslated, so simply translate the text you need from it and run lrelease on the ts file. Then load this file in addition to your original .qm file(s) when you load up your translation file(s). For the OK and Cancel buttons you would need to translate their text in the QDialogButtonBox section.
The example below demonstrates how this can be done:
TEMPLATE = app SOURCES += main.cpp TRANSLATIONS = t1_fr.ts qt_custom.ts CONFIG += console
#include <QtGui>
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QTranslator trans(0);
trans.load("t1_fr", ".");
trans.load("qt_custom", ".");
a.installTranslator(&trans);
QMessageBox::warning(0, QObject::tr("Warning Title"),
QObject::tr("Warning Message"),
QMessageBox::Ok|QMessageBox::Cancel);
return a.exec();
}