Qt: Use locale-sensitive compare for game list sort

This commit is contained in:
TellowKrinkle
2023-10-15 01:11:35 -05:00
committed by TellowKrinkle
parent 3c05d000f5
commit 485f8a6d3a
3 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -438,7 +438,7 @@ bool GameListModel::titlesLessThan(int left_row, int right_row) const
const GameList::Entry* left = GameList::GetEntryByIndex(left_row);
const GameList::Entry* right = GameList::GetEntryByIndex(right_row);
return (StringUtil::Strcasecmp(left->GetTitleSort().c_str(), right->GetTitleSort().c_str()) < 0);
return QtHost::LocaleSensitiveCompare(QString::fromStdString(left->GetTitleSort()), QString::fromStdString(right->GetTitleSort())) < 0;
}
bool GameListModel::lessThan(const QModelIndex& left_index, const QModelIndex& right_index, int column) const
+3
View File
@@ -283,4 +283,7 @@ namespace QtHost
/// VM state, safe to access on UI thread.
bool IsVMValid();
bool IsVMPaused();
/// Compare strings in the locale of the current UI language
int LocaleSensitiveCompare(QStringView lhs, QStringView rhs);
} // namespace QtHost
+13
View File
@@ -66,6 +66,9 @@ namespace QtHost
static const GlyphInfo* GetGlyphInfo(const std::string_view& language);
static std::vector<ImWchar> s_glyph_ranges;
static QLocale s_current_locale;
static QCollator s_current_collator;
} // namespace QtHost
static std::vector<QTranslator*> s_translators;
@@ -112,6 +115,11 @@ void QtHost::InstallTranslator()
if (language == QStringLiteral("system"))
language = getSystemLanguage();
QString qlanguage = language;
qlanguage.replace('-', '_');
s_current_locale = QLocale(qlanguage);
s_current_collator = QCollator(s_current_locale);
// Install the base qt translation first.
#ifdef __APPLE__
const QString base_dir = QStringLiteral("%1/../Resources/translations").arg(qApp->applicationDirPath());
@@ -375,3 +383,8 @@ const QtHost::GlyphInfo* QtHost::GetGlyphInfo(const std::string_view& language)
return nullptr;
}
int QtHost::LocaleSensitiveCompare(QStringView lhs, QStringView rhs)
{
return s_current_collator.compare(lhs, rhs);
}