Let quassel honour locale language settings
authorBas Pape <baspape@gmail.com>
Fri, 23 Nov 2012 18:01:35 +0000 (19:01 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 19 Feb 2013 21:52:14 +0000 (22:52 +0100)
When the language setting (LC_MESSAGES) differs from the global locale
set, quassel will use the wrong language. Qt 4.8 introduces some changes
to QLocale which make this pretty much Just Work; this patch copies the
necessary bits for older Qts.

Fixes #1194

src/common/quassel.cpp

index e9763fc..c60f5ec 100644 (file)
@@ -40,6 +40,7 @@
 #include "bufferinfo.h"
 #include "types.h"
 #include "syncableobject.h"
 #include "bufferinfo.h"
 #include "types.h"
 #include "syncableobject.h"
+#include "logger.h"
 
 Quassel::BuildInfo Quassel::_buildInfo;
 AbstractCliParser *Quassel::_cliParser = 0;
 
 Quassel::BuildInfo Quassel::_buildInfo;
 AbstractCliParser *Quassel::_cliParser = 0;
@@ -494,10 +495,32 @@ void Quassel::loadTranslation(const QLocale &locale)
     quasselTranslator->setObjectName("QuasselTr");
     qApp->installTranslator(quasselTranslator);
 
     quasselTranslator->setObjectName("QuasselTr");
     qApp->installTranslator(quasselTranslator);
 
-    QLocale::setDefault(locale);
+#if QT_VERSION >= 0x040800
+    bool success = qtTranslator->load(locale, QString("qt_%1"), translationDirPath());
+    if (!success)
+        qtTranslator->load(locale, QString("qt_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
+    quasselTranslator->load(locale, QString(""), translationDirPath());
+#else
+    QString localeName = locale.name();
+
+    // if the user did not specify a language in the settings, the system locale
+    // is used, but Qt < 4.8 does not respect language settings. This bit is
+    // based on QLocale::uiLanguages() as in Qt 4.8.3
+    if (locale == QLocale::system()) {
+        // FIXME: does it make sense to set the locale to the system locale?
+        QLocale::setDefault(locale);
+        QVariant res = QSystemLocale().query(QSystemLocale::UILanguages, QVariant());
+        if (!res.isNull()) {
+            QString newName = res.toStringList()[0];
+            if (!newName.isEmpty()) {
+                localeName = newName.replace('-', "_"); // silly Qt.
+            }
+        }
+    }
 
 
-    bool success = qtTranslator->load(QString("qt_%1").arg(locale.name()), translationDirPath());
+    bool success = qtTranslator->load(QString("qt_%1").arg(localeName), translationDirPath());
     if (!success)
     if (!success)
-        qtTranslator->load(QString("qt_%1").arg(locale.name()), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
-    quasselTranslator->load(QString("%1").arg(locale.name()), translationDirPath());
+        qtTranslator->load(QString("qt_%1").arg(localeName), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
+    quasselTranslator->load(QString("%1").arg(localeName), translationDirPath());
+#endif
 }
 }