TranslationHandler now suggests a language based on sysytem locale.
Also made sure toolbar visibility is updated before saving settings.
This commit is contained in:
parent
a415ab1e5c
commit
7a4115236a
|
@ -167,11 +167,14 @@ void MainWindow::LoadSettings()
|
||||||
|
|
||||||
QString error = "";
|
QString error = "";
|
||||||
|
|
||||||
SetLanguage(mSettings->value(SETTINGS_LANGUAGE, 0).toInt());
|
SetLanguage(mSettings->value(SETTINGS_LANGUAGE, mTranslation->SuggestLanguage()).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::SaveSettings()
|
void MainWindow::SaveSettings()
|
||||||
{
|
{
|
||||||
|
//Force toolbar checkbox value to be updated
|
||||||
|
AboutToShowViewMenu();
|
||||||
|
|
||||||
mSettings->setValue(SETTINGS_WINDOW_WIDTH, size().width());
|
mSettings->setValue(SETTINGS_WINDOW_WIDTH, size().width());
|
||||||
mSettings->setValue(SETTINGS_WINDOW_HEIGHT, size().height());
|
mSettings->setValue(SETTINGS_WINDOW_HEIGHT, size().height());
|
||||||
mSettings->setValue(SETTINGS_WINDOW_MAXIMIZED, isMaximized());
|
mSettings->setValue(SETTINGS_WINDOW_MAXIMIZED, isMaximized());
|
||||||
|
|
|
@ -27,11 +27,11 @@ TranslationHandler::TranslationHandler(QObject *parent) :
|
||||||
mTranslator(new QTranslator(this))
|
mTranslator(new QTranslator(this))
|
||||||
{
|
{
|
||||||
//Add our default languages
|
//Add our default languages
|
||||||
mNames << QObject::tr("English")
|
mNames << "English"
|
||||||
<< QObject::tr("Finnish")
|
<< "Finnish"
|
||||||
<< QObject::tr("Swedish")
|
<< "Swedish"
|
||||||
<< QObject::tr("German")
|
<< "German"
|
||||||
<< QObject::tr("Russian");
|
<< "Russian";
|
||||||
|
|
||||||
mFiles << "cppcheck_en"
|
mFiles << "cppcheck_en"
|
||||||
<< "cppcheck_fi"
|
<< "cppcheck_fi"
|
||||||
|
@ -109,3 +109,30 @@ int TranslationHandler::GetCurrentLanguage() const
|
||||||
return mCurrentLanguage;
|
return mCurrentLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TranslationHandler::SuggestLanguage() const
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Get language from system locale's name
|
||||||
|
QLocale::languageToString would return the languages full name and we
|
||||||
|
only want two-letter ISO 639 language code so we'll get it from
|
||||||
|
locale's name.
|
||||||
|
*/
|
||||||
|
QString language = QLocale::system().name().left(2);
|
||||||
|
//qDebug()<<"Your language is"<<language;
|
||||||
|
|
||||||
|
//catenate that to the default language filename
|
||||||
|
QString file = QString("cppcheck_%1").arg(language);
|
||||||
|
//qDebug()<<"Language file could be"<<file;
|
||||||
|
|
||||||
|
|
||||||
|
//And see if we can find it from our list of language files
|
||||||
|
int index = mFiles.indexOf(file);
|
||||||
|
|
||||||
|
//If nothing found, return english
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
const QStringList GetFiles();
|
const QStringList GetFiles();
|
||||||
bool SetLanguage(const int index, QString &error);
|
bool SetLanguage(const int index, QString &error);
|
||||||
int GetCurrentLanguage() const;
|
int GetCurrentLanguage() const;
|
||||||
|
int SuggestLanguage() const;
|
||||||
protected:
|
protected:
|
||||||
int mCurrentLanguage;
|
int mCurrentLanguage;
|
||||||
QStringList mNames;
|
QStringList mNames;
|
||||||
|
|
Loading…
Reference in New Issue