forked from qt-creator/qt-creator
Sort language setting options
It was arbitrary from the file system. Fixes: QTCREATORBUG-31262 Change-Id: I3b5a0940a59be85a61468b7fe7336ca481ffcc7a Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -218,18 +218,18 @@ static bool hasQmFilesForLocale(const QString &locale, const QString &creatorTrP
|
|||||||
|
|
||||||
void GeneralSettingsWidget::fillLanguageBox() const
|
void GeneralSettingsWidget::fillLanguageBox() const
|
||||||
{
|
{
|
||||||
const QString currentLocale = language();
|
const QString currentLocale = Core::ICore::isQtDesignStudio() ? QString("C") : language();
|
||||||
|
|
||||||
m_languageBox->addItem(Tr::tr("<System Language>"), QString());
|
m_languageBox->addItem(Tr::tr("<System Language>"), QString());
|
||||||
|
|
||||||
|
using Item = std::pair<QString, QString>;
|
||||||
|
QList<Item> items;
|
||||||
// need to add this explicitly, since there is no qm file for English
|
// need to add this explicitly, since there is no qm file for English
|
||||||
m_languageBox->addItem(QLatin1String("English"), QLatin1String("C"));
|
items.append({QString("English"), QString("C")});
|
||||||
if (currentLocale == QLatin1String("C") || Core::ICore::isQtDesignStudio())
|
|
||||||
m_languageBox->setCurrentIndex(m_languageBox->count() - 1);
|
|
||||||
|
|
||||||
const FilePath creatorTrPath = ICore::resourcePath("translations");
|
const FilePath creatorTrPath = ICore::resourcePath("translations");
|
||||||
const FilePaths languageFiles = creatorTrPath.dirEntries(
|
const FilePaths languageFiles = creatorTrPath.dirEntries(
|
||||||
QStringList(QLatin1String("qtcreator*.qm")));
|
QStringList(QLatin1String("qtcreator*.qm")));
|
||||||
|
|
||||||
for (const FilePath &languageFile : languageFiles) {
|
for (const FilePath &languageFile : languageFiles) {
|
||||||
const QString name = languageFile.fileName();
|
const QString name = languageFile.fileName();
|
||||||
int start = name.indexOf('_') + 1;
|
int start = name.indexOf('_') + 1;
|
||||||
@@ -240,11 +240,16 @@ void GeneralSettingsWidget::fillLanguageBox() const
|
|||||||
QLocale tmpLocale(locale);
|
QLocale tmpLocale(locale);
|
||||||
QString languageItem = QLocale::languageToString(tmpLocale.language()) + QLatin1String(" (")
|
QString languageItem = QLocale::languageToString(tmpLocale.language()) + QLatin1String(" (")
|
||||||
+ QLocale::territoryToString(tmpLocale.territory()) + QLatin1Char(')');
|
+ QLocale::territoryToString(tmpLocale.territory()) + QLatin1Char(')');
|
||||||
m_languageBox->addItem(languageItem, locale);
|
items.append({languageItem, locale});
|
||||||
if (locale == currentLocale)
|
|
||||||
m_languageBox->setCurrentIndex(m_languageBox->count() - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
void GeneralSettingsWidget::apply()
|
||||||
|
Reference in New Issue
Block a user