Skip to content

Commit

Permalink
Simplify code for translation loading
Browse files Browse the repository at this point in the history
Don't have two identical loops for loading languages from files and from
resources.
  • Loading branch information
MKleusberg committed May 18, 2015
1 parent 8aa72c9 commit a342194
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,34 +394,18 @@ void PreferencesDialog::fillLanguageBox()
"en_US");
}

// append availeble *.qm files from translation dir near executable
foreach(const QFileInfo &file, translationsDir.entryInfoList())
// Get available *.qm files from translation dir near executable as well as from resources
QFileInfoList file_infos = translationsDir.entryInfoList();
file_infos += QDir(":/translations").entryInfoList();
foreach(const QFileInfo &file, file_infos)
{
QLocale locale(file.baseName().remove("sqlb_"));

// Skip invalid locales
if(locale.name() == "C")
continue;

QString language = QLocale::languageToString(locale.language()) + " (" +
QLocale::countryToString(locale.country()) + ")";

if (locale == systemLocale)
language += " [System language]";

ui->languageComboBox->addItem(QIcon(":/flags/" + locale.name()), language, locale.name());
}

// append *.qm files from resources
foreach (const QFileInfo &file, QDir(":/translations").entryInfoList())
{
QLocale locale(file.baseName().remove("sqlb_"));

// Skip invalid locales
if(locale.name() == "C")
continue;

// Translation for this locale already loaded in previous foreach
// Skip translations that were already loaded
if (ui->languageComboBox->findData(locale.name(), Qt::UserRole, Qt::MatchExactly) != -1)
continue;

Expand Down

0 comments on commit a342194

Please sign in to comment.