diff options
author | Fabian Müller <fmueller@owncloud.com> | 2021-03-15 19:16:45 +0300 |
---|---|---|
committer | Fabian Müller <80399010+fmoc@users.noreply.github.com> | 2021-03-31 12:43:26 +0300 |
commit | 3ecdfcc97636c3fb160aa86a12c7cb67b6d682f6 (patch) | |
tree | 5abef86f232c751439c7a23975f89fd2e341087b | |
parent | 79979c82e8cc67f7fe3b608506d5215c3025f272 (diff) |
Add --language parameter
Can be used by users to overwrite the language, e.g., for testing, or if the auto-detection doesn't work.
-rw-r--r-- | docs/modules/ROOT/pages/advanced_usage/command_line_options.adoc | 3 | ||||
-rw-r--r-- | src/gui/application.cpp | 45 | ||||
-rw-r--r-- | src/gui/application.h | 1 |
3 files changed, 33 insertions, 16 deletions
diff --git a/docs/modules/ROOT/pages/advanced_usage/command_line_options.adoc b/docs/modules/ROOT/pages/advanced_usage/command_line_options.adoc index 5cd5efbf4..14c8e7df1 100644 --- a/docs/modules/ROOT/pages/advanced_usage/command_line_options.adoc +++ b/docs/modules/ROOT/pages/advanced_usage/command_line_options.adoc @@ -46,4 +46,7 @@ This command is used with `--logdir`. | `--confdir <dirname>` | Uses the specified configuration directory. + +| `--language <locale>` +| Enforce language specified by given locale in the user interface. Example values: `de_DE`, `en_US`, `nl_NL` |=== diff --git a/src/gui/application.cpp b/src/gui/application.cpp index b5fb46ddd..451c1d4a5 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -74,19 +74,20 @@ namespace { const QString optionsC() { return QStringLiteral( - "Options:\n" - " -h --help : show this help screen.\n" - " -s --showsettings : show the settings dialog while starting.\n" - " -q --quit : quit the running instance\n" - " --logfile <filename> : write log output to file <filename>.\n" - " --logfile - : write log output to stdout.\n" - " --logdir <name> : write each sync log output in a new file\n" - " in folder <name>.\n" - " --logexpire <hours> : removes logs older than <hours> hours.\n" - " (to be used with --logdir)\n" - " --logflush : flush the log file after every write.\n" - " --logdebug : also output debug-level messages in the log.\n" - " --confdir <dirname> : Use the given configuration folder."); + "Options:\n" + " -h --help : show this help screen.\n" + " -s --showsettings : show the settings dialog while starting.\n" + " -q --quit : quit the running instance\n" + " --logfile <filename> : write log output to file <filename>.\n" + " --logfile - : write log output to stdout.\n" + " --logdir <name> : write each sync log output in a new file\n" + " in folder <name>.\n" + " --logexpire <hours> : removes logs older than <hours> hours.\n" + " (to be used with --logdir)\n" + " --logflush : flush the log file after every write.\n" + " --logdebug : also output debug-level messages in the log.\n" + " --language <locale> : override UI language\n" + " --confdir <dirname> : Use the given configuration folder."); } QString applicationTrPath() @@ -621,6 +622,12 @@ void Application::parseOptions(const QStringList &options) _debugMode = true; } else if (option == QLatin1String("--version")) { _versionOnly = true; + } else if (option == QLatin1String("--language")) { + if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) { + _userEnforcedLanguage = it.next(); + } else { + showHint("--language expects a parameter"); + } } else if (option.endsWith(QStringLiteral(APPLICATION_DOTVIRTUALFILE_SUFFIX))) { // virtual file, open it after the Folder were created (if the app is not terminated) QTimer::singleShot(0, this, [this, option] { openVirtualFile(option); }); @@ -707,9 +714,15 @@ void Application::setupTranslations() { QStringList uiLanguages = QLocale::system().uiLanguages(); - QString enforcedLocale = Theme::instance()->enforcedLocale(); - if (!enforcedLocale.isEmpty()) - uiLanguages.prepend(enforcedLocale); + // allow user and theme to enforce a language via a commandline parameter + const auto themeEnforcedLocale = Theme::instance()->enforcedLocale(); + // note that the user enforced language is prioritized over the theme enforced one + // as we are prepending to the list of languages, the list passed to the loop must be sorted with ascending priority + for (const auto &enforcedLocale : { themeEnforcedLocale, _userEnforcedLanguage }) { + if (!enforcedLocale.isEmpty()) { + uiLanguages.prepend(enforcedLocale); + } + } QTranslator *translator = new QTranslator(this); QTranslator *qtTranslator = new QTranslator(this); diff --git a/src/gui/application.h b/src/gui/application.h index e44f1e486..0e37cdb6a 100644 --- a/src/gui/application.h +++ b/src/gui/application.h @@ -136,6 +136,7 @@ private: bool _logDebug; bool _userTriggeredConnect; bool _debugMode; + QString _userEnforcedLanguage; ClientProxy _proxy; |