mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 19:16:16 +00:00
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>
This commit is contained in:
parent
c260ec5c16
commit
7813ac86bf
3 changed files with 23 additions and 36 deletions
13
main.cpp
13
main.cpp
|
@ -13,22 +13,13 @@
|
|||
|
||||
#include <QStringList>
|
||||
|
||||
QTranslator *qtTranslator, *ssrfTranslator;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
bool no_filenames = true;
|
||||
#if 0
|
||||
const char *path;
|
||||
|
||||
/* set up l18n - the search directory needs to change
|
||||
* so that it uses the correct system directory when
|
||||
* subsurface isn't run from the local directory */
|
||||
path = subsurface_gettext_domainpath(argv[0]);
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain("subsurface", path);
|
||||
bind_textdomain_codeset("subsurface", "utf-8");
|
||||
textdomain("subsurface");
|
||||
#endif
|
||||
setup_system_prefs();
|
||||
prefs = default_prefs;
|
||||
|
||||
|
|
42
qt-gui.cpp
42
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");
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#include <QString>
|
||||
#include <stdint.h>
|
||||
#include "dive.h"
|
||||
#include <QTranslator>
|
||||
|
||||
// global pointers for our translation
|
||||
extern QTranslator *qtTranslator, *ssrfTranslator;
|
||||
|
||||
class DiveComputerNode {
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue