#include <typeinfo>
#include <QDebug>
+#include <QDir>
+#include <QLibraryInfo>
+#include <QMessageBox>
+#include <QWidget>
#include <boost/version.hpp>
setOrganizationDomain("sigrok.org");
}
+const QStringList Application::get_languages() const
+{
+ 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;
+}
+
+const QString Application::get_language_editors(const QString& language) const
+{
+ if (language == "de") return "Sören Apel, Uwe Hermann";
+ if (language == "es_mx") return "Carlos Diaz";
+
+ return QString();
+}
+
void Application::switch_language(const QString& language)
{
removeTranslator(&app_translator_);
removeTranslator(&qt_translator_);
+ removeTranslator(&qtbase_translator_);
if ((language != "C") && (language != "en")) {
// Application translations
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();
}
}