diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 53c85e4b21370..fc3478c9c23ae 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -97,6 +97,7 @@ namespace { " --overridelocaldir : specify a local dir to be used in the account setup wizard.\n" " --userid : userId (username as on the server) to pass when creating an account via command-line.\n" " --apppassword : appPassword to pass when creating an account via command-line.\n" + " --set-language : specify a language to use for the client, regardless of the OS language.\n" " --localdirpath : (optional) path where to create a local sync folder when creating an account via command-line.\n" " --isvfsenabled : whether to set a VFS or non-VFS folder (1 for 'yes' or 0 for 'no') when creating an account via command-line.\n" " --remotedirpath : (optional) path to a remote subfolder when creating an account via command-line.\n" @@ -362,6 +363,12 @@ Application::Application(int &argc, char **argv) shouldExit = true; } + if (!_setLanguage.isNull()) { + // checking for .isNull here as setting the value to an empty string will use the OS language again + cfg.setLanguage(_setLanguage); + shouldExit = true; + } + if (AccountSetupCommandLineManager::instance()) { cfg.setVfsEnabled(AccountSetupCommandLineManager::instance()->isVfsEnabled()); } @@ -881,6 +888,10 @@ void Application::parseOptions(const QStringList &options) } else { showHint("Invalid URL passed to --overridelocaldir"); } + } else if (option == QStringLiteral("--set-language")) { + if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) { + _setLanguage = it.next(); + } } else if (option == QStringLiteral("--forcelegacyconfigimport")) { AccountManager::instance()->setForceLegacyImport(true); } else { @@ -1001,10 +1012,22 @@ QString substLang(const QString &lang) return lang; } +QString enforcedLanguage() +{ + const ConfigFile cfg; + const auto configLanguage = cfg.language(); + if (!configLanguage.isEmpty()) { + // always prefer value from configuration + return configLanguage; + } + + return Theme::instance()->enforcedLocale(); +} + void Application::setupTranslations() { qCInfo(lcApplication) << "System UI languages are:" << QLocale::system().uiLanguages(); - const auto enforcedLocale = Theme::instance()->enforcedLocale(); + const auto enforcedLocale = enforcedLanguage(); const auto lang = substLang(!enforcedLocale.isEmpty() ? enforcedLocale : QLocale::system().uiLanguages(QLocale::TagSeparator::Underscore).first()); qCInfo(lcApplication) << "selected application language:" << lang; diff --git a/src/gui/application.h b/src/gui/application.h index c3936da43a45e..ab1465be22764 100644 --- a/src/gui/application.h +++ b/src/gui/application.h @@ -150,6 +150,7 @@ protected slots: QString _overrideServerUrl; QString _overrideLocalDir; + QString _setLanguage; #if defined(WITH_CRASHREPORTER) QScopedPointer _crashHandler; diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 1efd01e5da355..17b9f145a2a43 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -115,6 +115,8 @@ static const QString defaultUpdateChannelName = "stable"; static const QStringList enterpriseUpdateChannelsList { QStringLiteral("stable"), QStringLiteral("enterprise") }; static const QString defaultEnterpriseChannel = "enterprise"; +static constexpr char languageC[] = "language"; + static constexpr int deleteFilesThresholdDefaultValue = 100; } @@ -1252,6 +1254,17 @@ void ConfigFile::setDesktopEnterpriseChannel(const QString &channel) settings.setValue(QLatin1String(desktopEnterpriseChannelName), channel); } +QString ConfigFile::language() const +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value(QLatin1String(languageC), QLatin1String("")).toString(); +} + +void ConfigFile::setLanguage(const QString& language) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue(QLatin1String(languageC), language); +} Q_GLOBAL_STATIC(QString, g_configFileName) diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index f38fba1f11ab0..c5e8e7049dfaf 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -241,6 +241,10 @@ class OWNCLOUDSYNC_EXPORT ConfigFile [[nodiscard]] QString desktopEnterpriseChannel() const; void setDesktopEnterpriseChannel(const QString &channel); + /// Enforce a specific language used for the UI + [[nodiscard]] QString language() const; + void setLanguage(const QString &language); + /** Returns a new settings pre-set in a specific group. The Settings will be created with the given parent. If no parent is specified, the caller must destroy the settings */ static std::unique_ptr settingsWithGroup(const QString &group, QObject *parent = nullptr);