X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fapplication.cpp;h=6f666c5c308762c55ea0990297f1ea9fea1536eb;hp=e933f96214d94c72620a088f7e766e8a675b574b;hb=49fee853b3f56ba78810260c71c3c402067f09fe;hpb=0466001be51e779b23aaebec1cc9361305c07be9 diff --git a/pv/application.cpp b/pv/application.cpp index e933f962..6f666c5c 100644 --- a/pv/application.cpp +++ b/pv/application.cpp @@ -21,6 +21,10 @@ #include #include +#include +#include +#include +#include #include @@ -61,10 +65,27 @@ Application::Application(int &argc, char* argv[]) : setOrganizationDomain("sigrok.org"); } +QStringList Application::get_languages() +{ + QStringList files = QDir(":/l10n/").entryList(QStringList("*.qm"), QDir::Files); + + QStringList result; + result << "en"; // Add default language to the set + + // Remove file extensions + for (const QString& file : files) + result << file.split(".").front(); + + result.sort(Qt::CaseInsensitive); + + return result; +} + void Application::switch_language(const QString& language) { removeTranslator(&app_translator_); removeTranslator(&qt_translator_); + removeTranslator(&qtbase_translator_); if ((language != "C") && (language != "en")) { // Application translations @@ -75,11 +96,34 @@ void Application::switch_language(const QString& language) qWarning() << "Translation resource" << resource << "not found"; // Qt translations - resource = ":/l10n/qtbase_" + language +".qm"; - if (qt_translator_.load(resource)) + QString tr_path(QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + + if (qt_translator_.load("qt_" + language, tr_path)) installTranslator(&qt_translator_); else - qWarning() << "Translation resource" << resource << "not found"; + qWarning() << "QT translations for" << language << "not found at" << + tr_path << ", Qt translations package is probably missing"; + + // Qt base translations + if (qtbase_translator_.load("qtbase_" + language, tr_path)) + installTranslator(&qtbase_translator_); + else + qWarning() << "QT base translations for" << language << "not found at" << + tr_path << ", Qt translations package is probably missing"; + } + + if (!topLevelWidgets().empty()) { + // Force all windows to update + for (QWidget *widget : topLevelWidgets()) + widget->update(); + + QMessageBox msg(topLevelWidgets().front()); + msg.setText(tr("Some parts of the application may still " \ + "use the previous language. Re-opening the affected windows or " \ + "restarting the application will remedy this.")); + msg.setStandardButtons(QMessageBox::Ok); + msg.setIcon(QMessageBox::Information); + msg.exec(); } }