Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <lang> : 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"
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/gui/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ protected slots:

QString _overrideServerUrl;
QString _overrideLocalDir;
QString _setLanguage;

#if defined(WITH_CRASHREPORTER)
QScopedPointer<CrashReporter::Handler> _crashHandler;
Expand Down
13 changes: 13 additions & 0 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions src/libsync/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QSettings> settingsWithGroup(const QString &group, QObject *parent = nullptr);
Expand Down