File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
173173void 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 ());
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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 ;
3637protected:
3738 int mCurrentLanguage ;
3839 QStringList mNames ;
You can’t perform that action at this time.
0 commit comments