diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 448144112..8f5c8171d 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -281,7 +281,7 @@ void initApp(int& argc, char** argv, bool doInitQSettings) QStringLiteral("org.flightgear.FlightGear.desktop")); #endif QTranslator* fallbackTranslator = new QTranslator(static_qApp.get()); - if (!fallbackTranslator->load(QLatin1String(":/FlightGear_en_US.qm"))) { + if (!fallbackTranslator->load(QLatin1String(":/FlightGear_en.qm"))) { qWarning() << "Failed to load default (en) translations"; delete fallbackTranslator; } else { @@ -289,7 +289,19 @@ void initApp(int& argc, char** argv, bool doInitQSettings) } QTranslator* translator = new QTranslator(static_qApp.get()); - if (translator->load(QLocale(), QLatin1String("FlightGear"), QLatin1String("_"), QLatin1String(":/"))) { + // check for --langauge=xx option and prefer that over QLocale + // detection of the locale if it exists + auto lang = Options::getArgValue(argc, argv, "--language"); + if (!lang.empty()) { + QString localeFile = "FlightGear_" + QString::fromStdString(lang); + if (translator->load(localeFile, QLatin1String(":/"))) { + qInfo() << "Loaded translations based on --language from:" << localeFile; + static_qApp->installTranslator(translator); + } else { + qInfo() << "--langauge was set, but no translations found at:" << localeFile; + delete translator; + } + } else if (translator->load(QLocale(), QLatin1String("FlightGear"), QLatin1String("_"), QLatin1String(":/"))) { // QLocale().name() looks like ' "it_IT" ' (without the outer // quotes) when running FG on Linux with LANG=it_IT.UTF-8. qInfo() << "Loaded translations for locale" << QLocale().name(); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index ab36190a0..389ea0698 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -251,7 +251,7 @@ void fgSetDefaults () v->setValueReadOnly("build-type", FG_BUILD_TYPE); char* envp = ::getenv( "http_proxy" ); - if( envp != NULL ) + if( envp != nullptr ) fgSetupProxy( envp ); } @@ -2960,7 +2960,7 @@ bool Options::checkForArg(int argc, char* argv[], const char* checkArg) { for (int i = 0; i < argc; ++i) { char* arg = argv[i]; - if (arg == 0) { + if (arg == nullptr) { continue; } @@ -2981,4 +2981,24 @@ bool Options::checkForArg(int argc, char* argv[], const char* checkArg) return false; } +std::string Options::getArgValue(int argc, char* argv[], const char* checkArg) +{ + const auto len = strlen(checkArg); + for (int i = 0; i < argc; ++i) { + char* arg = argv[i]; + if (arg == nullptr) { + continue; + } + + if (strncmp(arg, checkArg, len) == 0) { + const auto alen = strlen(arg); + if ((alen - len) < 2) + return {}; // no value after the =, or missing = entirely + return std::string(arg + len + 1); + } + } // of args iteration + + return {}; +} + } // of namespace flightgear diff --git a/src/Main/options.hxx b/src/Main/options.hxx index ee3434a99..4cd3bd995 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -155,6 +155,17 @@ public: */ static bool checkForArg(int argc, char* argv[], const char* arg); + /** + * @brief getArgValue - get the value of an argument if it exists, or + * an empty string otherwise + * @param argc + * @param argv + * @param checkArg : arg to look for, with '--' prefix + * @return value following '=' until the next white space + */ + static std::string getArgValue(int argc, char* argv[], const char* checkArg); + + SGPath platformDefaultRoot() const; /**