From 43a2974baac0d0c2d37df372c4a678866a1c2f6a Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 18 Jul 2024 10:29:41 +0200 Subject: [PATCH] Sort language setting options It was arbitrary from the file system. Fixes: QTCREATORBUG-31262 Change-Id: I3b5a0940a59be85a61468b7fe7336ca481ffcc7a Reviewed-by: hjk --- src/plugins/coreplugin/generalsettings.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/plugins/coreplugin/generalsettings.cpp b/src/plugins/coreplugin/generalsettings.cpp index 934cd167cbc..728798fb23d 100644 --- a/src/plugins/coreplugin/generalsettings.cpp +++ b/src/plugins/coreplugin/generalsettings.cpp @@ -218,18 +218,18 @@ static bool hasQmFilesForLocale(const QString &locale, const QString &creatorTrP void GeneralSettingsWidget::fillLanguageBox() const { - const QString currentLocale = language(); + const QString currentLocale = Core::ICore::isQtDesignStudio() ? QString("C") : language(); m_languageBox->addItem(Tr::tr(""), QString()); + + using Item = std::pair; + QList items; // need to add this explicitly, since there is no qm file for English - m_languageBox->addItem(QLatin1String("English"), QLatin1String("C")); - if (currentLocale == QLatin1String("C") || Core::ICore::isQtDesignStudio()) - m_languageBox->setCurrentIndex(m_languageBox->count() - 1); + items.append({QString("English"), QString("C")}); const FilePath creatorTrPath = ICore::resourcePath("translations"); const FilePaths languageFiles = creatorTrPath.dirEntries( QStringList(QLatin1String("qtcreator*.qm"))); - for (const FilePath &languageFile : languageFiles) { const QString name = languageFile.fileName(); int start = name.indexOf('_') + 1; @@ -240,11 +240,16 @@ void GeneralSettingsWidget::fillLanguageBox() const QLocale tmpLocale(locale); QString languageItem = QLocale::languageToString(tmpLocale.language()) + QLatin1String(" (") + QLocale::territoryToString(tmpLocale.territory()) + QLatin1Char(')'); - m_languageBox->addItem(languageItem, locale); - if (locale == currentLocale) - m_languageBox->setCurrentIndex(m_languageBox->count() - 1); + items.append({languageItem, locale}); } } + + Utils::sort(items, &Item::first); + for (const Item &i : std::as_const(items)) { + m_languageBox->addItem(i.first, i.second); + if (i.second == currentLocale) + m_languageBox->setCurrentIndex(m_languageBox->count() - 1); + } } void GeneralSettingsWidget::apply()