I have a problem with translate standard buttons in QMessageBox. If I check the language, the buttons are translated very well, but if I don't check the language, the buttons are not translated. How can I get translated buttons without checking the language every time when I need to show QMessageBox?
#include "application.h"
#include "main_window.h"
#include <QTranslator>
#include <qlibraryinfo.h>
int main( int argc, char *argv[] )
{
Application application( argc, argv );
QString language = app()->settings().value("language").toString();
if (language == "Russian") // Here I check the language
{
QTranslator translator_ru;
if (translator_ru.load(QString("translations/qtbase_ru.qm")))
application.installTranslator(&translator_ru);
if (QMessageBox::question(0, "Delete?", "First test") == QMessageBox::Yes) {} // In this message, the standard buttons are in Russian
}
if (QMessageBox::question(0, "Delete?", "Second test") == QMessageBox::Yes) {} // In this message, the standard buttons are in English
MainWindow window;
window.show();
return application.exec();
}
I've found the solution: