From 097310504c6614da4e1fd2251404c8b4ec81ac5f Mon Sep 17 00:00:00 2001 From: Alexey Remizov Date: Thu, 26 Jun 2025 00:49:02 +0300 Subject: [PATCH] Add plural keys for albums and tracks --- res/translations/ru.json | 14 ++++++++++++++ ui/browsing/albumpage.go | 6 +++++- ui/browsing/favoritespage.go | 6 +++++- ui/browsing/playlistpage.go | 6 +++++- ui/browsing/playlistspage.go | 5 ++++- ui/widgets/gridview.go | 5 ++++- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/res/translations/ru.json b/res/translations/ru.json index 2e419ab..bbd38a4 100644 --- a/res/translations/ru.json +++ b/res/translations/ru.json @@ -277,5 +277,19 @@ "few": "{{.trackCount}} композиции добавлены в список воспроизведения", "many": "{{.trackCount}} композиций добавлены в список воспроизведения", "other": "{{.trackCount}} композиций добавлены в список воспроизведения" + }, + + "{{.trackCount}} tracks": { + "one": "{{.trackCount}} композиция", + "few": "{{.trackCount}} композиции", + "many": "{{.trackCount}} композиций", + "other": "{{.trackCount}} композиций" + }, + + "{{.albumsCount}} albums": { + "one": "{{.albumsCount}} альбом", + "few": "{{.albumsCount}} альбома", + "many": "{{.albumsCount}} альбомов", + "other": "{{.albumsCount}} альбомов" } } diff --git a/ui/browsing/albumpage.go b/ui/browsing/albumpage.go index 8df71c9..0223958 100644 --- a/ui/browsing/albumpage.go +++ b/ui/browsing/albumpage.go @@ -3,6 +3,7 @@ package browsing import ( "fmt" "log" + "strconv" "strings" "github.com/dweymouth/supersonic/backend" @@ -396,11 +397,14 @@ func formatMiscLabelStr(a *mediaprovider.AlbumWithTracks) string { if a.TrackCount == 1 { tracks = lang.L("track") } + fallbackTracksMsg := fmt.Sprintf("%d %s", a.TrackCount, tracks) + tracksMsg := lang.LocalizePluralKey("{{.trackCount}} tracks", + fallbackTracksMsg, a.TrackCount, map[string]string{"trackCount": strconv.Itoa(a.TrackCount)}) yearStr := util.FormatItemDate(a.Date) if y := a.ReissueDate.Year; y != nil && *y > a.YearOrZero() { yearStr += fmt.Sprintf(" (%s %s)", lang.L("reissued"), util.FormatItemDate(a.ReissueDate)) } - return fmt.Sprintf("%s · %d %s · %s%s", yearStr, a.TrackCount, tracks, discs, util.SecondsToTimeString(float64(a.Duration))) + return fmt.Sprintf("%s · %s · %s%s", yearStr, tracksMsg, discs, util.SecondsToTimeString(float64(a.Duration))) } func (s *albumPageState) Restore() Page { diff --git a/ui/browsing/favoritespage.go b/ui/browsing/favoritespage.go index e75850b..4ef3000 100644 --- a/ui/browsing/favoritespage.go +++ b/ui/browsing/favoritespage.go @@ -3,6 +3,7 @@ package browsing import ( "fmt" "log" + "strconv" "github.com/dweymouth/supersonic/backend" "github.com/dweymouth/supersonic/backend/mediaprovider" @@ -389,11 +390,14 @@ func buildArtistGridViewModel(artists []*mediaprovider.Artist) []widgets.GridVie if ar.AlbumCount == 1 { albums = lang.L("album") } + fallbackAlbumsMsg := fmt.Sprintf("%d %s", ar.AlbumCount, albums) + albumsMsg := lang.LocalizePluralKey("{{.albumsCount}} albums", + fallbackAlbumsMsg, ar.AlbumCount, map[string]string{"albumsCount": strconv.Itoa(ar.AlbumCount)}) model = append(model, widgets.GridViewItemModel{ ID: ar.ID, CoverArtID: ar.CoverArtID, Name: ar.Name, - Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albums)}, + Secondary: []string{albumsMsg}, CanFavorite: true, IsFavorite: ar.Favorite, }) diff --git a/ui/browsing/playlistpage.go b/ui/browsing/playlistpage.go index b3681cf..a9b3cf1 100644 --- a/ui/browsing/playlistpage.go +++ b/ui/browsing/playlistpage.go @@ -3,6 +3,7 @@ package browsing import ( "fmt" "log" + "strconv" "strings" "github.com/deluan/sanitize" @@ -510,7 +511,10 @@ func (a *PlaylistPageHeader) formatPlaylistTrackTimeStr(p *mediaprovider.Playlis } else { tracks = lang.L("tracks") } - return fmt.Sprintf("%d %s, %s", p.TrackCount, tracks, util.SecondsToTimeString(float64(p.Duration))) + fallbackTracksMsg := fmt.Sprintf("%d %s", p.TrackCount, tracks) + tracksMsg := lang.LocalizePluralKey("{{.trackCount}} tracks", + fallbackTracksMsg, p.TrackCount, map[string]string{"trackCount": strconv.Itoa(p.TrackCount)}) + return fmt.Sprintf("%s, %s", tracksMsg, util.SecondsToTimeString(float64(p.Duration))) } func (s *playlistPageState) Restore() Page { diff --git a/ui/browsing/playlistspage.go b/ui/browsing/playlistspage.go index 5571b96..5bea3b5 100644 --- a/ui/browsing/playlistspage.go +++ b/ui/browsing/playlistspage.go @@ -206,11 +206,14 @@ func createPlaylistGridViewModel(playlists []*mediaprovider.Playlist) []widgets. } else { tracks = lang.L("tracks") } + fallbackTracksMsg := fmt.Sprintf("%d %s", pl.TrackCount, tracks) + tracksMsg := lang.LocalizePluralKey("{{.trackCount}} tracks", + fallbackTracksMsg, pl.TrackCount, map[string]string{"trackCount": strconv.Itoa(pl.TrackCount)}) return widgets.GridViewItemModel{ Name: pl.Name, ID: pl.ID, CoverArtID: pl.CoverArtID, - Secondary: []string{fmt.Sprintf("%d %s", pl.TrackCount, tracks)}, + Secondary: []string{tracksMsg}, } }) } diff --git a/ui/widgets/gridview.go b/ui/widgets/gridview.go index cd02fc3..5f502b1 100644 --- a/ui/widgets/gridview.go +++ b/ui/widgets/gridview.go @@ -98,11 +98,14 @@ func (g gridViewArtistIterator) NextN(n int) []GridViewItemModel { if ar.AlbumCount == 1 { albumsLabel = lang.L("album") } + fallbackAlbumsMsg := fmt.Sprintf("%d %s", ar.AlbumCount, albumsLabel) + albumsMsg := lang.LocalizePluralKey("{{.albumsCount}} albums", + fallbackAlbumsMsg, ar.AlbumCount, map[string]string{"albumsCount": strconv.Itoa(ar.AlbumCount)}) return GridViewItemModel{ Name: ar.Name, ID: ar.ID, CoverArtID: ar.CoverArtID, - Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albumsLabel)}, + Secondary: []string{albumsMsg}, CanFavorite: true, IsFavorite: ar.Favorite, }