summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-11-23 02:25:49 +0100
committerPetr Mrázek <peterix@gmail.com>2016-11-23 02:25:49 +0100
commit295c6e808ab15c8f10326d375c7c4cdd80531e5f (patch)
tree5ffe145745fc4d94151b261b734354c9cc404773
parent7a14b639574fb7139761c7ca4986fa03e99b7366 (diff)
downloadMultiMC-295c6e808ab15c8f10326d375c7c4cdd80531e5f.tar
MultiMC-295c6e808ab15c8f10326d375c7c4cdd80531e5f.tar.gz
MultiMC-295c6e808ab15c8f10326d375c7c4cdd80531e5f.tar.lz
MultiMC-295c6e808ab15c8f10326d375c7c4cdd80531e5f.tar.xz
MultiMC-295c6e808ab15c8f10326d375c7c4cdd80531e5f.zip
NOISSUE fix translation listing in settings and translation loading
It was impossible to select and load translations properly.
-rw-r--r--application/MultiMC.cpp14
-rw-r--r--application/pages/global/MultiMCPage.cpp34
2 files changed, 33 insertions, 15 deletions
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index 6c7deca1..2a903437 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -406,15 +406,17 @@ void MultiMC::initNetwork()
void MultiMC::initTranslations()
{
- QLocale locale(m_settings->get("Language").toString());
+ auto bcp47Name = m_settings->get("Language").toString();
+ QLocale locale(bcp47Name);
QLocale::setDefault(locale);
- qDebug() << "Your language is" << locale.bcp47Name();
+ qDebug() << "Your language is" << bcp47Name;
+ // FIXME: this is likely never present.
m_qt_translator.reset(new QTranslator());
- if (m_qt_translator->load("qt_" + locale.bcp47Name(),
+ if (m_qt_translator->load("qt_" + bcp47Name,
QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
{
qDebug() << "Loading Qt Language File for"
- << locale.bcp47Name().toLocal8Bit().constData() << "...";
+ << bcp47Name.toLocal8Bit().constData() << "...";
if (!installTranslator(m_qt_translator.get()))
{
qCritical() << "Loading Qt Language File failed.";
@@ -427,10 +429,10 @@ void MultiMC::initTranslations()
}
m_mmc_translator.reset(new QTranslator());
- if (m_mmc_translator->load("mmc_" + locale.bcp47Name(), FS::PathCombine(QDir::currentPath(), "translations")))
+ if (m_mmc_translator->load("mmc_" + bcp47Name, FS::PathCombine(QDir::currentPath(), "translations")))
{
qDebug() << "Loading MMC Language File for"
- << locale.bcp47Name().toLocal8Bit().constData() << "...";
+ << bcp47Name.toLocal8Bit().constData() << "...";
if (!installTranslator(m_mmc_translator.get()))
{
qCritical() << "Loading MMC Language File failed.";
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<QString, QString>;
+ std::vector<LanguageItem> 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());