Skip to content

Commit 7a41152

Browse files
committed
TranslationHandler now suggests a language based on sysytem locale.
Also made sure toolbar visibility is updated before saving settings.
1 parent a415ab1 commit 7a41152

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

gui/mainwindow.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,14 @@ void MainWindow::LoadSettings()
167167

168168
QString error = "";
169169

170-
SetLanguage(mSettings->value(SETTINGS_LANGUAGE, 0).toInt());
170+
SetLanguage(mSettings->value(SETTINGS_LANGUAGE, mTranslation->SuggestLanguage()).toInt());
171171
}
172172

173173
void MainWindow::SaveSettings()
174174
{
175+
//Force toolbar checkbox value to be updated
176+
AboutToShowViewMenu();
177+
175178
mSettings->setValue(SETTINGS_WINDOW_WIDTH, size().width());
176179
mSettings->setValue(SETTINGS_WINDOW_HEIGHT, size().height());
177180
mSettings->setValue(SETTINGS_WINDOW_MAXIMIZED, isMaximized());

gui/translationhandler.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ TranslationHandler::TranslationHandler(QObject *parent) :
2727
mTranslator(new QTranslator(this))
2828
{
2929
//Add our default languages
30-
mNames << QObject::tr("English")
31-
<< QObject::tr("Finnish")
32-
<< QObject::tr("Swedish")
33-
<< QObject::tr("German")
34-
<< QObject::tr("Russian");
30+
mNames << "English"
31+
<< "Finnish"
32+
<< "Swedish"
33+
<< "German"
34+
<< "Russian";
3535

3636
mFiles << "cppcheck_en"
3737
<< "cppcheck_fi"
@@ -109,3 +109,30 @@ int TranslationHandler::GetCurrentLanguage() const
109109
return mCurrentLanguage;
110110
}
111111

112+
int TranslationHandler::SuggestLanguage() const
113+
{
114+
/*
115+
Get language from system locale's name
116+
QLocale::languageToString would return the languages full name and we
117+
only want two-letter ISO 639 language code so we'll get it from
118+
locale's name.
119+
*/
120+
QString language = QLocale::system().name().left(2);
121+
//qDebug()<<"Your language is"<<language;
122+
123+
//catenate that to the default language filename
124+
QString file = QString("cppcheck_%1").arg(language);
125+
//qDebug()<<"Language file could be"<<file;
126+
127+
128+
//And see if we can find it from our list of language files
129+
int index = mFiles.indexOf(file);
130+
131+
//If nothing found, return english
132+
if (index < 0)
133+
{
134+
return 0;
135+
}
136+
137+
return index;
138+
}

gui/translationhandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TranslationHandler : QObject
3333
const QStringList GetFiles();
3434
bool SetLanguage(const int index, QString &error);
3535
int GetCurrentLanguage() const;
36+
int SuggestLanguage() const;
3637
protected:
3738
int mCurrentLanguage;
3839
QStringList mNames;

0 commit comments

Comments
 (0)