1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Less noise when switching languages in launcher

* Check if .qm file exists
* Don't call installTranslator() for English

Fixes #4277
This commit is contained in:
Alexander Wilms 2024-07-18 17:29:46 +02:00
parent d02251f6a8
commit 6599db4461
2 changed files with 42 additions and 10 deletions

View File

@ -236,16 +236,32 @@ void MainWindow::on_aboutButton_clicked()
void MainWindow::updateTranslation()
{
#ifdef ENABLE_QT_TRANSLATIONS
const std::string translationFile = settings["general"]["language"].String() + ".qm";
logGlobal->info("Loading translation '%s'", translationFile);
const std::string translationFile = settings["general"]["language"].String()+ ".qm";
QString translationFileResourcePath = QString{":/translation/%1"}.arg(translationFile.c_str());
if (!translator.load(QString{":/translation/%1"}.arg(translationFile.c_str())))
logGlobal->info("Loading translation %s", translationFile);
if(!QFile::exists(translationFileResourcePath))
{
logGlobal->error("Failed to load translation");
logGlobal->warn("Translation file %s does not exist", translationFileResourcePath.toStdString());
return;
}
if (!translator.load(translationFileResourcePath))
{
logGlobal->error("Failed to load translation file %s", translationFileResourcePath.toStdString());
return;
}
if(translationFile == "english.qm")
{
// translator doesn't need to be installed for English
return;
}
if (!qApp->installTranslator(&translator))
logGlobal->error("Failed to install translator");
{
logGlobal->error("Failed to install translator for translation file %s", translationFileResourcePath.toStdString());
}
#endif
}

View File

@ -133,17 +133,33 @@ void MainWindow::parseCommandLine(ExtractionOptions & extractionOptions)
void MainWindow::loadTranslation()
{
#ifdef ENABLE_QT_TRANSLATIONS
const std::string translationFile = settings["general"]["language"].String() + ".qm";
logGlobal->info("Loading translation '%s'", translationFile);
const std::string translationFile = settings["general"]["language"].String()+ ".qm";
QString translationFileResourcePath = QString{":/translation/%1"}.arg(translationFile.c_str());
if (!translator.load(QString{":/translation/%1"}.arg(translationFile.c_str())))
logGlobal->info("Loading translation %s", translationFile);
if(!QFile::exists(translationFileResourcePath))
{
logGlobal->error("Failed to load translation");
logGlobal->warn("Translation file %s does not exist", translationFileResourcePath.toStdString());
return;
}
if (!translator.load(translationFileResourcePath))
{
logGlobal->error("Failed to load translation file %s", translationFileResourcePath.toStdString());
return;
}
if(translationFile == "english.qm")
{
// translator doesn't need to be installed for English
return;
}
if (!qApp->installTranslator(&translator))
logGlobal->error("Failed to install translator");
{
logGlobal->error("Failed to install translator for translation file %s", translationFileResourcePath.toStdString());
}
#endif
}