Qt: Fix translation of %n hours

This commit is contained in:
Stenzek 2024-05-17 13:07:23 +10:00
parent e444eb713a
commit a59a42f35b
No known key found for this signature in database
3 changed files with 15 additions and 2 deletions

View file

@ -1065,7 +1065,7 @@ TinyString GameList::FormatTimespan(std::time_t timespan, bool long_format)
else else
{ {
if (hours > 0) if (hours > 0)
ret.format(TRANSLATE_FS("GameList", "{} hours"), hours); ret.assign(TRANSLATE_PLURAL_STR("GameList", "%n hours", "", hours));
else else
ret.assign(TRANSLATE_PLURAL_STR("GameList", "%n minutes", "", minutes)); ret.assign(TRANSLATE_PLURAL_STR("GameList", "%n minutes", "", minutes));
} }

View file

@ -213,6 +213,17 @@ void GameListModel::invalidateCoverForPath(const std::string& path)
emit dataChanged(mi, mi, {Qt::DecorationRole}); emit dataChanged(mi, mi, {Qt::DecorationRole});
} }
QString GameListModel::formatTimespan(time_t timespan)
{
// avoid an extra string conversion
const u32 hours = static_cast<u32>(timespan / 3600);
const u32 minutes = static_cast<u32>((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 int GameListModel::getCoverArtWidth() const
{ {
return std::max(static_cast<int>(static_cast<float>(COVER_ART_WIDTH) * m_cover_scale), 1); return std::max(static_cast<int>(static_cast<float>(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) if (ge->total_played_time == 0)
return {}; return {};
else else
return QtUtils::StringViewToQString(GameList::FormatTimespan(ge->total_played_time)); return formatTimespan(ge->total_played_time);
} }
case Column_LastPlayed: case Column_LastPlayed:

View file

@ -84,6 +84,8 @@ private:
void loadOrGenerateCover(const GameList::Entry* ge); void loadOrGenerateCover(const GameList::Entry* ge);
void invalidateCoverForPath(const std::string& path); void invalidateCoverForPath(const std::string& path);
static QString formatTimespan(time_t timespan);
float m_cover_scale = 0.0f; float m_cover_scale = 0.0f;
bool m_show_titles_for_covers = false; bool m_show_titles_for_covers = false;