Launcher respects --language arg if set
This commit is contained in:
parent
2b1913e118
commit
f819750287
3 changed files with 47 additions and 4 deletions
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue