From 295c6e808ab15c8f10326d375c7c4cdd80531e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 23 Nov 2016 02:25:49 +0100 Subject: NOISSUE fix translation listing in settings and translation loading It was impossible to select and load translations properly. --- application/pages/global/MultiMCPage.cpp | 34 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'application/pages/global/MultiMCPage.cpp') diff --git a/application/pages/global/MultiMCPage.cpp b/application/pages/global/MultiMCPage.cpp index e9b19ac6..03b0c1be 100644 --- a/application/pages/global/MultiMCPage.cpp +++ b/application/pages/global/MultiMCPage.cpp @@ -262,8 +262,7 @@ void MultiMCPage::applySettings() auto s = MMC->settings(); // Language - s->set("Language", - ui->languageBox->itemData(ui->languageBox->currentIndex()).toLocale().bcp47Name()); + s->set("Language", ui->languageBox->itemData(ui->languageBox->currentIndex()).toString()); if (ui->resetNotificationsBtn->isChecked()) { @@ -352,15 +351,32 @@ void MultiMCPage::loadSettings() { auto s = MMC->settings(); // Language - ui->languageBox->clear(); - ui->languageBox->addItem(tr("English"), QLocale(QLocale::English)); - for(const QString & lang: QDir("translations").entryList(QStringList() << "*.qm", QDir::Files)) { - QLocale locale(lang.section(QRegExp("[_\\.]"), 1)); - ui->languageBox->addItem(QLocale::languageToString(locale.language()), locale); + using LanguageItem = std::pair; + std::vector items; + + QLocale english("en"); + items.push_back(std::make_pair(english.nativeLanguageName(), "en")); + for(QString lang: QDir("translations").entryList(QStringList() << "*.qm", QDir::Files)) + { + lang.remove(".qm"); + lang.remove("mmc_"); + QLocale locale(lang); + QString fullLangName = locale.nativeLanguageName(); + qDebug() << fullLangName << lang; + items.push_back(std::make_pair(fullLangName, lang)); + } + std::sort(items.begin(), items.end(), [](const LanguageItem & a, const LanguageItem & b) + { + return a.first.localeAwareCompare(b.first) < 0; + }); + ui->languageBox->clear(); + for(auto & item: items) + { + ui->languageBox->addItem(item.first, item.second); + } + ui->languageBox->setCurrentIndex(ui->languageBox->findData(s->get("Language").toString())); } - ui->languageBox->setCurrentIndex( - ui->languageBox->findData(QLocale(s->get("Language").toString()))); // Updates ui->autoUpdateCheckBox->setChecked(s->get("AutoUpdate").toBool()); -- cgit v1.2.3