GUI: Better handling of unknown language loading.
If there were unknown language in settings the fallback to English language didn't work as expected. And there were no proper current language set after that. Initialize current language to English so we always have English as proper fallback.
This commit is contained in:
parent
1e0d538273
commit
e15bc488c9
|
@ -410,10 +410,8 @@ void MainWindow::ProgramSettings()
|
||||||
dialog.SaveFullPath(),
|
dialog.SaveFullPath(),
|
||||||
dialog.SaveAllErrors(),
|
dialog.SaveAllErrors(),
|
||||||
dialog.ShowNoErrorsMessage());
|
dialog.ShowNoErrorsMessage());
|
||||||
const QString currentLang = mTranslation->GetCurrentLanguage();
|
|
||||||
const QString newLang = mSettings->value(SETTINGS_LANGUAGE, "en").toString();
|
const QString newLang = mSettings->value(SETTINGS_LANGUAGE, "en").toString();
|
||||||
if (currentLang != newLang)
|
SetLanguage(newLang);
|
||||||
SetLanguage(newLang);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,20 +648,18 @@ void MainWindow::FormatAndSetTitle(const QString &text)
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::SetLanguage(const QString &code)
|
void MainWindow::SetLanguage(const QString &code)
|
||||||
{
|
{
|
||||||
if (mTranslation->GetCurrentLanguage() == code)
|
const QString currentLang = mTranslation->GetCurrentLanguage();
|
||||||
{
|
if (currentLang == code)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
if (!mTranslation->SetLanguage(code, error))
|
if (!mTranslation->SetLanguage(code, error))
|
||||||
{
|
{
|
||||||
QMessageBox msg(QMessageBox::Critical,
|
QMessageBox msg(QMessageBox::Critical,
|
||||||
tr("Cppcheck"),
|
tr("Cppcheck"),
|
||||||
QString(tr("Failed to change the language:\n\n%1\n\n")).arg(error),
|
QString(tr("Failed to change the language:\n\n%1")).arg(error),
|
||||||
QMessageBox::Ok,
|
QMessageBox::Ok,
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
TranslationHandler::TranslationHandler(QObject *parent) :
|
TranslationHandler::TranslationHandler(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
|
mCurrentLanguage("en"),
|
||||||
mTranslator(new QTranslator(this))
|
mTranslator(new QTranslator(this))
|
||||||
{
|
{
|
||||||
// Add our available languages
|
// Add our available languages
|
||||||
|
@ -85,7 +86,7 @@ bool TranslationHandler::SetLanguage(const QString &code, QString &error)
|
||||||
int index = GetLanguageIndexByCode(code);
|
int index = GetLanguageIndexByCode(code);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
error = QObject::tr("Incorrect language specified!");
|
error = QObject::tr("Unknown language specified!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue