summaryrefslogtreecommitdiffstats
path: root/qt-gui.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-10-08 22:25:02 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-10-08 23:11:25 -0700
commit7813ac86bf5bfaeee3d4652b35dcfd8972775423 (patch)
treee055e7dd4b8497248d4528732715cb638da8257c /qt-gui.cpp
parentc260ec5c1673f9071b0c9c5407944ecb35bf5ff2 (diff)
downloadsubsurface-7813ac86bf5bfaeee3d4652b35dcfd8972775423.tar.gz
Load translations at run time
This doesn't enable translation switching, but at least we try and load the correct translation at startup. We create two global pointers for the currently active translations. This also removes the remainders of the gettext()/glib based translation system. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-gui.cpp')
-rw-r--r--qt-gui.cpp42
1 files changed, 17 insertions, 25 deletions
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 08eb9d538..5127b7ba8 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -36,6 +36,7 @@
#include <QNetworkProxy>
#include <QDateTime>
#include <QRegExp>
+#include <QLibraryInfo>
#include <gettextfromc.h>
#define tr(arg) gettextFromC::instance()->tr(arg)
@@ -45,31 +46,6 @@ const char *default_dive_computer_product;
const char *default_dive_computer_device;
DiveComputerList dcList;
-#if 0
-class Translator: public QTranslator
-{
- Q_OBJECT
-
-public:
- Translator(QObject *parent = 0);
- ~Translator() {}
-
- virtual QString translate(const char *context, const char *sourceText,
- const char *disambiguation = NULL) const;
-};
-
-Translator::Translator(QObject *parent):
- QTranslator(parent)
-{
-}
-
-QString Translator::translate(const char *context, const char *sourceText,
- const char *disambiguation) const
-{
- return gettext(sourceText);
-}
-#endif
-
static QApplication *application = NULL;
static MainWindow *window = NULL;
@@ -108,6 +84,22 @@ void init_ui(int *argcp, char ***argvp)
QCoreApplication::setApplicationName("Subsurface");
xslt_path = strdup(getSubsurfaceDataPath("xslt").toAscii().data());
+ QLocale loc;
+ if (loc.uiLanguages().first() != "en-US") {
+ qtTranslator = new QTranslator;
+ if (qtTranslator->load(loc,"qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
+ application->installTranslator(qtTranslator);
+ } else {
+ qDebug() << "can't find Qt localization for locale" << loc.uiLanguages().first();
+ }
+ ssrfTranslator = new QTranslator;
+ if (ssrfTranslator->load(loc,"subsurface", "_")) {
+ application->installTranslator(ssrfTranslator);
+ } else {
+ qDebug() << "can't find Subsurface localization for locale" << loc.uiLanguages().first();
+ }
+ }
+
QSettings s;
s.beginGroup("GeneralSettings");
prefs.default_filename = getSetting(s, "default_filename");