summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-08-27 22:14:52 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-08-27 22:14:52 (GMT)
commit7bd7321e2f6a55cccb51b13bcb642ce0093972d1 (patch)
tree62fa2647fb59dcc2a17d935e34d108ce31f5f1cb
parentdaf43a0f9d03193e3e920c1b920783292a87ec78 (diff)
Make marble-qt find the KDE-translator/packaging based qm catalog files
BUG: 367781
-rw-r--r--src/apps/marble-qt/qtmain.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/apps/marble-qt/qtmain.cpp b/src/apps/marble-qt/qtmain.cpp
index 47d05e5..eea61db 100644
--- a/src/apps/marble-qt/qtmain.cpp
+++ b/src/apps/marble-qt/qtmain.cpp
@@ -14,6 +14,7 @@
#include <QDir>
#include <QLocale>
#include <QTranslator>
+#include <QStandardPaths>
#include "QtMainWindow.h"
@@ -38,6 +39,48 @@
using namespace Marble;
+// load translation file from normal "KDE Applications" packaging installation
+static bool loadTranslation(const QString &localeDirName, QApplication &app)
+{
+ const QString subPath = QLatin1String("locale/") + localeDirName + QLatin1String("/LC_MESSAGES/marble_qt.qm");
+ const QString fullPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, subPath);
+ if (fullPath.isEmpty()) {
+ return false;
+ }
+
+ QTranslator* translator = new QTranslator(&app);
+ if (!translator->load(fullPath)) {
+ delete translator;
+ return false;
+ }
+
+ app.installTranslator(translator);
+
+ return true;
+}
+
+// load KDE translators system based translations
+// TODO: document other possible supported translation systems, if any, and where their catalog files are
+static void loadTranslations(QApplication &app)
+{
+ // Quote from ecm_create_qm_loader created code:
+ // The way Qt translation system handles plural forms makes it necessary to
+ // have a translation file which contains only plural forms for `en`.
+ // That's why we load the `en` translation unconditionally, then load the
+ // translation for the current locale to overload it.
+ const QString en(QStringLiteral("en"));
+
+ loadTranslation(en, app);
+
+ QLocale locale = QLocale::system();
+ if (locale.name() != en) {
+ if (!loadTranslation(locale.name(), app)) {
+ loadTranslation(locale.bcp47Name(), app);
+ }
+ }
+}
+
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
@@ -46,10 +89,9 @@ int main(int argc, char *argv[])
app.setOrganizationDomain( "kde.org" );
// Widget translation
- QString lang = QLocale::system().name().section(QLatin1Char('_'), 0, 0);
- QTranslator translator;
- translator.load(QLatin1String("marble-") + lang, MarbleDirs::path(QStringLiteral("lang")));
- app.installTranslator(&translator);
+ // Load Qt translation system catalog for libmarblewidget, the plugins and this app
+ loadTranslations(app);
+
app.setApplicationDisplayName(MainWindow::tr("Marble - Virtual Globe"));
// For non static builds on mac and win