From 0acb15de0f332f4a7e4547750397d98d36a4cdfe Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Thu, 7 Mar 2024 23:09:00 +0100 Subject: [PATCH] Set test locale to C --- src/cli/keepassxc-cli.cpp | 3 ++- src/core/Bootstrap.cpp | 4 ++-- src/core/Bootstrap.h | 2 +- src/core/Translator.cpp | 8 +++----- src/core/Translator.h | 2 +- src/gui/Application.cpp | 4 ++-- src/gui/Application.h | 2 +- src/main.cpp | 2 +- tests/TestCli.cpp | 1 + tests/gui/TestGui.cpp | 1 + 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/cli/keepassxc-cli.cpp b/src/cli/keepassxc-cli.cpp index 120c706472..abf1b0efde 100644 --- a/src/cli/keepassxc-cli.cpp +++ b/src/cli/keepassxc-cli.cpp @@ -24,6 +24,7 @@ #include "Utils.h" #include "config-keepassx.h" #include "core/Bootstrap.h" +#include "core/Config.h" #include "core/Metadata.h" #include "core/Tools.h" #include "crypto/Crypto.h" @@ -181,7 +182,7 @@ int main(int argc, char** argv) QCoreApplication app(argc, argv); QCoreApplication::setApplicationVersion(KEEPASSXC_VERSION); - Bootstrap::bootstrap(); + Bootstrap::bootstrap(config()->get(Config::GUI_Language).toString()); Utils::setDefaultTextStreams(); Commands::setupCommands(false); diff --git a/src/core/Bootstrap.cpp b/src/core/Bootstrap.cpp index aa359a29b2..4b1bc90c9f 100644 --- a/src/core/Bootstrap.cpp +++ b/src/core/Bootstrap.cpp @@ -63,7 +63,7 @@ namespace Bootstrap * Perform early application bootstrapping that does not rely on a QApplication * being present. */ - void bootstrap() + void bootstrap(const QString& uiLanguage) { #ifdef QT_NO_DEBUG disableCoreDumps(); @@ -72,7 +72,7 @@ namespace Bootstrap setupSearchPaths(); applyEarlyQNetworkAccessManagerWorkaround(); - Translator::installTranslators(); + Translator::installTranslators(uiLanguage); } // LCOV_EXCL_START diff --git a/src/core/Bootstrap.h b/src/core/Bootstrap.h index f458e05b25..bd2006cbb3 100644 --- a/src/core/Bootstrap.h +++ b/src/core/Bootstrap.h @@ -22,7 +22,7 @@ namespace Bootstrap { - void bootstrap(); + void bootstrap(const QString& uiLanguage = "system"); void disableCoreDumps(); bool createWindowsDACL(); void setupSearchPaths(); diff --git a/src/core/Translator.cpp b/src/core/Translator.cpp index e8a535447c..2101e8dc15 100644 --- a/src/core/Translator.cpp +++ b/src/core/Translator.cpp @@ -25,24 +25,22 @@ #include #include -#include "core/Config.h" #include "core/Resources.h" /** * Install all KeePassXC and Qt translators. */ -void Translator::installTranslators() +void Translator::installTranslators(const QString& uiLanguage) { QStringList languages; - QString languageSetting = config()->get(Config::GUI_Language).toString(); - if (languageSetting.isEmpty() || languageSetting == "system") { + if (uiLanguage.isEmpty() || uiLanguage == "system") { // NOTE: this is a workaround for the terrible way Qt loads languages // using the QLocale::uiLanguages() approach. Instead, we search each // language and all country variants in order before moving to the next. QLocale locale; languages = locale.uiLanguages(); } else { - languages << languageSetting; + languages << uiLanguage; } // Always try to load english last diff --git a/src/core/Translator.h b/src/core/Translator.h index c0c5f1d3c3..3e073c1724 100644 --- a/src/core/Translator.h +++ b/src/core/Translator.h @@ -24,7 +24,7 @@ class Translator { public: - static void installTranslators(); + static void installTranslators(const QString& uiLanguage = "system"); static QList> availableLanguages(); private: diff --git a/src/gui/Application.cpp b/src/gui/Application.cpp index f8fb56b72f..5916b0b81f 100644 --- a/src/gui/Application.cpp +++ b/src/gui/Application.cpp @@ -147,9 +147,9 @@ Application::~Application() * configuration OS security properties, and loading translators. * A QApplication object has to be instantiated before calling this function. */ -void Application::bootstrap() +void Application::bootstrap(const QString& uiLanguage) { - Bootstrap::bootstrap(); + Bootstrap::bootstrap(uiLanguage); #ifdef Q_OS_WIN // Qt on Windows uses "MS Shell Dlg 2" as the default font for many widgets, which resolves diff --git a/src/gui/Application.h b/src/gui/Application.h index 48928650b3..937d9d3865 100644 --- a/src/gui/Application.h +++ b/src/gui/Application.h @@ -41,7 +41,7 @@ class Application : public QApplication Application(int& argc, char** argv); ~Application() override; - static void bootstrap(); + static void bootstrap(const QString& uiLanguage = "system"); void applyTheme(); diff --git a/src/main.cpp b/src/main.cpp index 0faa2c06ba..f0c987fac4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -176,7 +176,7 @@ int main(int argc, char** argv) QGuiApplication::setDesktopFileName(app.property("KPXC_QUALIFIED_APPNAME").toString() + QStringLiteral(".desktop")); #endif - Application::bootstrap(); + Application::bootstrap(config()->get(Config::GUI_Language).toString()); MainWindow mainWindow; #ifdef Q_OS_WIN diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp index ba1f84a490..fa15716378 100644 --- a/tests/TestCli.cpp +++ b/tests/TestCli.cpp @@ -66,6 +66,7 @@ void TestCli::initTestCase() QVERIFY(Crypto::init()); Config::createTempFileInstance(); + QLocale::setDefault(QLocale::c()); Bootstrap::bootstrap(); m_devNull.reset(new QFile()); diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 57d1392bcc..fc5edbc99d 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -89,6 +89,7 @@ void TestGui::initTestCase() { QVERIFY(Crypto::init()); Config::createTempFileInstance(); + QLocale::setDefault(QLocale::c()); Application::bootstrap(); m_mainWindow.reset(new MainWindow());