summaryrefslogtreecommitdiff
path: root/ui/qt/wireshark_application.cpp
diff options
context:
space:
mode:
authorMichal Labedzki <michal.labedzki@tieto.com>2013-12-21 17:55:43 +0100
committerMichal Labedzki <michal.labedzki@tieto.com>2014-11-04 08:21:55 +0000
commit5025bc258cdeabbd498919d5c6b4554accdad842 (patch)
tree53301fcaa347e0a933086ce102b56b27e13aeee9 /ui/qt/wireshark_application.cpp
parent15e78de432f55f5478f1b3994f3d7e060b60508d (diff)
downloadwireshark-5025bc258cdeabbd498919d5c6b4554accdad842.tar.gz
Qt: Dynamic languages
- get language as soon as possible (before creating any Qt objects) to make all translations working - dynamic list of supported languages - runtime change of GUI language (no need to restart application) - add flags icons support - search for *.qm languages in buildin resources, then data dir called "languages" (main directory in sources or /usr/share/wireshark/languages), then user directory (UNIX: ~/.wireshark/languages); "languages" directory should contains files wireshark_xx.qm where xx is language code (en, en_GB, etc.), and optional xx.svg for flag icon - try to fix some untranslated manually-created UI items (need manual reset text of those components) Change-Id: I62ca8a8cddce47cec9dbcad6b0bd68b6cfd92229 Reviewed-on: https://code.wireshark.org/review/5041 Tested-by: Michal Labedzki <michal.labedzki@tieto.com> Reviewed-by: Michal Labedzki <michal.labedzki@tieto.com>
Diffstat (limited to 'ui/qt/wireshark_application.cpp')
-rw-r--r--ui/qt/wireshark_application.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp
index 1362ca7f6b..a4f3595438 100644
--- a/ui/qt/wireshark_application.cpp
+++ b/ui/qt/wireshark_application.cpp
@@ -61,6 +61,8 @@
#include <QEvent>
#include <QFileOpenEvent>
#include <QFontMetrics>
+#include <QLibraryInfo>
+#include <QLocale>
#include <QMutableListIterator>
#include <QTimer>
#include <QUrl>
@@ -570,6 +572,7 @@ WiresharkApplication::WiresharkApplication(int &argc, char **argv) :
Q_INIT_RESOURCE(status);
Q_INIT_RESOURCE(toolbar);
Q_INIT_RESOURCE(wsicon);
+ Q_INIT_RESOURCE(languages);
#ifdef Q_OS_WIN
/* RichEd20.DLL is needed for native file dialog filter entries. */
@@ -866,6 +869,43 @@ void WiresharkApplication::addRecentItem(const QString &filename, qint64 size, b
itemStatusFinished(filename, size, accessible);
}
+static void switchTranslator(QTranslator& myTranslator, const QString& filename,
+ const QString& searchPath)
+{
+ wsApp->removeTranslator(&myTranslator);
+
+ if (myTranslator.load(filename, searchPath))
+ wsApp->installTranslator(&myTranslator);
+}
+
+void WiresharkApplication::loadLanguage(const QString& newLanguage)
+{
+ QLocale locale;
+ QString localeLanguage;
+
+ if (newLanguage.isEmpty() || newLanguage == "auto") {
+ localeLanguage = QLocale::system().name();
+ } else {
+ localeLanguage = newLanguage;
+ }
+
+ locale = QLocale(localeLanguage);
+ QLocale::setDefault(locale);
+ switchTranslator(wsApp->translator,
+ QString("wireshark_%1.qm").arg(localeLanguage), QString(":/i18n/"));
+ if (QFile::exists(QString("%1/%2/wireshark_%3.qm")
+ .arg(get_datafile_dir()).arg("languages").arg(localeLanguage)))
+ switchTranslator(wsApp->translator,
+ QString("wireshark_%1.qm").arg(localeLanguage), QString(get_datafile_dir()) + QString("/languages"));
+ if (QFile::exists(QString("%1/wireshark_%3.qm")
+ .arg(gchar_free_to_qstring(get_persconffile_path("languages", FALSE))).arg(localeLanguage)))
+ switchTranslator(wsApp->translator,
+ QString("wireshark_%1.qm").arg(localeLanguage), gchar_free_to_qstring(get_persconffile_path("languages", FALSE)));
+ switchTranslator(wsApp->translatorQt,
+ QString("qt_%1.qm").arg(localeLanguage),
+ QLibraryInfo::location(QLibraryInfo::TranslationsPath));
+}
+
/*
* Editor modelines
*