From a59a42f35bbf6eb664b06314778d886555fa5429 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 17 May 2024 13:07:23 +1000 Subject: [PATCH] Qt: Fix translation of %n hours --- src/core/game_list.cpp | 2 +- src/duckstation-qt/gamelistmodel.cpp | 13 ++++++++++++- src/duckstation-qt/gamelistmodel.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index addf6f336..60e9a4aba 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -1065,7 +1065,7 @@ TinyString GameList::FormatTimespan(std::time_t timespan, bool long_format) else { if (hours > 0) - ret.format(TRANSLATE_FS("GameList", "{} hours"), hours); + ret.assign(TRANSLATE_PLURAL_STR("GameList", "%n hours", "", hours)); else ret.assign(TRANSLATE_PLURAL_STR("GameList", "%n minutes", "", minutes)); } diff --git a/src/duckstation-qt/gamelistmodel.cpp b/src/duckstation-qt/gamelistmodel.cpp index fa732698e..075c3eb38 100644 --- a/src/duckstation-qt/gamelistmodel.cpp +++ b/src/duckstation-qt/gamelistmodel.cpp @@ -213,6 +213,17 @@ void GameListModel::invalidateCoverForPath(const std::string& path) emit dataChanged(mi, mi, {Qt::DecorationRole}); } +QString GameListModel::formatTimespan(time_t timespan) +{ + // avoid an extra string conversion + const u32 hours = static_cast(timespan / 3600); + const u32 minutes = static_cast((timespan % 3600) / 60); + if (hours > 0) + return qApp->translate("GameList", "%n hours", "", hours); + else + return qApp->translate("GameList", "%n minutes", "", minutes); +} + int GameListModel::getCoverArtWidth() const { return std::max(static_cast(static_cast(COVER_ART_WIDTH) * m_cover_scale), 1); @@ -316,7 +327,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const if (ge->total_played_time == 0) return {}; else - return QtUtils::StringViewToQString(GameList::FormatTimespan(ge->total_played_time)); + return formatTimespan(ge->total_played_time); } case Column_LastPlayed: diff --git a/src/duckstation-qt/gamelistmodel.h b/src/duckstation-qt/gamelistmodel.h index c3e8c51d0..7a1e5faf9 100644 --- a/src/duckstation-qt/gamelistmodel.h +++ b/src/duckstation-qt/gamelistmodel.h @@ -84,6 +84,8 @@ private: void loadOrGenerateCover(const GameList::Entry* ge); void invalidateCoverForPath(const std::string& path); + static QString formatTimespan(time_t timespan); + float m_cover_scale = 0.0f; bool m_show_titles_for_covers = false;