aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--helpers.h1
-rw-r--r--qt-gui.cpp45
-rw-r--r--qt-ui/usermanual.cpp14
3 files changed, 41 insertions, 19 deletions
diff --git a/helpers.h b/helpers.h
index fbcf2895f..445e9135c 100644
--- a/helpers.h
+++ b/helpers.h
@@ -32,6 +32,7 @@ int parseTemperatureToMkelvin(const QString &text);
QString get_dive_date_string(timestamp_t when);
QString get_short_dive_date_string(timestamp_t when);
QString get_trip_date_string(timestamp_t when, int nr);
+QString uiLanguage(QLocale *callerLoc);
#define M_OR_FT(_m, _f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : (feet_to_mm(_f)))
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 3e898b979..224fdd597 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -76,9 +76,36 @@ void init_qt(int *argcp, char ***argvp)
application = new QApplication(*argcp, *argvp);
}
+QString uiLanguage(QLocale *callerLoc)
+{
+ QSettings s;
+ s.beginGroup("Language");
+ QLocale loc;
+
+ if (!s.value("UseSystemLanguage", true).toBool()) {
+ loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString());
+ }
+
+ QString uiLang = loc.uiLanguages().first();
+ s.endGroup();
+
+ // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info
+ if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) {
+ QLocale loc2(loc.bcp47Name());
+ loc = loc2;
+ uiLang = loc2.uiLanguages().first();
+ }
+ if (callerLoc)
+ *callerLoc = loc;
+
+ return uiLang;
+}
+
void init_ui(void)
{
QVariant v;
+ QSettings s;
+
// tell Qt to use system proxies
// note: on Linux, "system" == "environment variables"
QNetworkProxyFactory::setUseSystemConfiguration(true);
@@ -102,24 +129,8 @@ void init_ui(void)
QCoreApplication::setApplicationName("Subsurface");
// find plugins installed in the application directory (without this SVGs don't work on Windows)
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());
-
- QSettings s;
- s.beginGroup("Language");
QLocale loc;
-
- if (!s.value("UseSystemLanguage", true).toBool()) {
- loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString());
- }
-
- QString uiLang = loc.uiLanguages().first();
- s.endGroup();
-
- // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info
- if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) {
- QLocale loc2(loc.bcp47Name());
- loc = loc2;
- uiLang = loc2.uiLanguages().first();
- }
+ QString uiLang = uiLanguage(&loc);
// we don't have translations for English - if we don't check for this
// Qt will proceed to load the second language in preference order - not what we want
diff --git a/qt-ui/usermanual.cpp b/qt-ui/usermanual.cpp
index 82691594c..3985b6cd4 100644
--- a/qt-ui/usermanual.cpp
+++ b/qt-ui/usermanual.cpp
@@ -1,10 +1,12 @@
#include <QDesktopServices>
#include <QShortcut>
+#include <QFile>
+#include <QDebug>
#include "usermanual.h"
#include "ui_usermanual.h"
-#include "../helpers.h"
+#include "helpers.h"
UserManual::UserManual(QWidget *parent) : QMainWindow(parent),
ui(new Ui::UserManual)
@@ -31,7 +33,15 @@ UserManual::UserManual(QWidget *parent) : QMainWindow(parent),
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
QString searchPath = getSubsurfaceDataPath("Documentation");
if (searchPath.size()) {
- QUrl url(searchPath.append("/user-manual.html"));
+ // look for localized versions of the manual first
+ QString lang = uiLanguage(NULL);
+ QString prefix = searchPath.append("/user-manual");
+ QFile manual(prefix + "_" + lang + ".html");
+ if (!manual.exists())
+ manual.setFileName(prefix + "_" + lang.left(2) + ".html");
+ if (!manual.exists())
+ manual.setFileName(prefix + ".html");
+ QUrl url(manual.fileName());
ui->webView->setUrl(url);
} else {
ui->webView->setHtml(tr("Cannot find the Subsurface manual"));