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:
Kimmo Varis 2011-02-08 18:22:44 +02:00
parent 1e0d538273
commit e15bc488c9
2 changed files with 6 additions and 9 deletions

View File

@ -410,10 +410,8 @@ void MainWindow::ProgramSettings()
dialog.SaveFullPath(),
dialog.SaveAllErrors(),
dialog.ShowNoErrorsMessage());
const QString currentLang = mTranslation->GetCurrentLanguage();
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);
}
void MainWindow::SetLanguage(const QString &code)
{
if (mTranslation->GetCurrentLanguage() == code)
{
const QString currentLang = mTranslation->GetCurrentLanguage();
if (currentLang == code)
return;
}
QString error;
if (!mTranslation->SetLanguage(code, error))
{
QMessageBox msg(QMessageBox::Critical,
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,
this);

View File

@ -24,6 +24,7 @@
TranslationHandler::TranslationHandler(QObject *parent) :
QObject(parent),
mCurrentLanguage("en"),
mTranslator(new QTranslator(this))
{
// Add our available languages
@ -85,7 +86,7 @@ bool TranslationHandler::SetLanguage(const QString &code, QString &error)
int index = GetLanguageIndexByCode(code);
if (index == -1)
{
error = QObject::tr("Incorrect language specified!");
error = QObject::tr("Unknown language specified!");
return false;
}