X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fapplication.cpp;h=6f666c5c308762c55ea0990297f1ea9fea1536eb;hp=5a6e28a1da996034aa24218df7ef2d66eb425543;hb=49fee853b3f56ba78810260c71c3c402067f09fe;hpb=f4ab4b5c657e5613caba82feaa81a8a400e4f331 diff --git a/pv/application.cpp b/pv/application.cpp index 5a6e28a1..6f666c5c 100644 --- a/pv/application.cpp +++ b/pv/application.cpp @@ -17,13 +17,14 @@ * along with this program; if not, see . */ -#include "application.hpp" -#include "config.h" - #include #include #include +#include +#include +#include +#include #include @@ -35,6 +36,10 @@ #include #endif +#include "application.hpp" +#include "config.h" +#include "globalsettings.hpp" + using std::cout; using std::endl; using std::exception; @@ -60,6 +65,74 @@ 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 + QString resource = ":/l10n/" + language +".qm"; + if (app_translator_.load(resource)) + installTranslator(&app_translator_); + else + qWarning() << "Translation resource" << resource << "not found"; + + // Qt translations + QString tr_path(QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + + if (qt_translator_.load("qt_" + language, tr_path)) + installTranslator(&qt_translator_); + else + 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(); + } +} + +void Application::on_setting_changed(const QString &key, const QVariant &value) +{ + if (key == pv::GlobalSettings::Key_General_Language) + switch_language(value.toString()); +} + void Application::collect_version_info(shared_ptr context) { // Library versions and features