Skip to content

Commit

Permalink
Merge pull request #427 from dweymouth/translations
Browse files Browse the repository at this point in the history
Prepare for translations
  • Loading branch information
dweymouth authored Jul 21, 2024
2 parents 8c5b5f5 + 1d216d0 commit 8145fbd
Show file tree
Hide file tree
Showing 41 changed files with 677 additions and 379 deletions.
20 changes: 7 additions & 13 deletions backend/mediaprovider/jellyfin/artistiterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ import (
"github.com/dweymouth/supersonic/sharedutil"
)

const (
ArtistSortAlbumCount string = "Album Count"
ArtistSortNameAZ string = "Name (A-Z)"
ArtistSortRandom string = "Random"
)

func (j *jellyfinMediaProvider) ArtistSortOrders() []string {
return []string{
ArtistSortAlbumCount,
ArtistSortNameAZ,
ArtistSortRandom,
mediaprovider.ArtistSortAlbumCount,
mediaprovider.ArtistSortNameAZ,
mediaprovider.ArtistSortRandom,
}
}

Expand All @@ -29,10 +23,10 @@ func (j *jellyfinMediaProvider) IterateArtists(sortOrder string, filter mediapro
var sortFn func([]*jellyfin.Artist) []*jellyfin.Artist

if sortOrder == "" {
sortOrder = ArtistSortNameAZ // default
sortOrder = mediaprovider.ArtistSortNameAZ // default
}
switch sortOrder {
case ArtistSortAlbumCount:
case mediaprovider.ArtistSortAlbumCount:
// Pagination needs to be disabled, to retrieve all results in a single request, and correctly sort them.
disablePagination = true
sortFn = func(artists []*jellyfin.Artist) []*jellyfin.Artist {
Expand All @@ -41,10 +35,10 @@ func (j *jellyfinMediaProvider) IterateArtists(sortOrder string, filter mediapro
})
return artists
}
case ArtistSortNameAZ:
case mediaprovider.ArtistSortNameAZ:
jfSort.Field = jellyfin.SortByName
jfSort.Mode = jellyfin.SortAsc
case ArtistSortRandom:
case mediaprovider.ArtistSortRandom:
jfSort.Field = jellyfin.SortByRandom
}

Expand Down
35 changes: 13 additions & 22 deletions backend/mediaprovider/jellyfin/iterators.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,35 @@ import (
"github.com/dweymouth/supersonic/sharedutil"
)

const (
AlbumSortRecentlyAdded string = "Recently Added"
AlbumSortRandom string = "Random"
AlbumSortTitleAZ string = "Title (A-Z)"
AlbumSortArtistAZ string = "Artist (A-Z)"
AlbumSortYearAscending string = "Year (ascending)"
AlbumSortYearDescending string = "Year (descending)"
)

func (j *jellyfinMediaProvider) AlbumSortOrders() []string {
return []string{
AlbumSortRecentlyAdded,
AlbumSortRandom,
AlbumSortTitleAZ,
AlbumSortArtistAZ,
AlbumSortYearAscending,
AlbumSortYearDescending,
mediaprovider.AlbumSortRecentlyAdded,
mediaprovider.AlbumSortRandom,
mediaprovider.AlbumSortTitleAZ,
mediaprovider.AlbumSortArtistAZ,
mediaprovider.AlbumSortYearAscending,
mediaprovider.AlbumSortYearDescending,
}
}

func (j *jellyfinMediaProvider) IterateAlbums(sortOrder string, filter mediaprovider.AlbumFilter) mediaprovider.AlbumIterator {
var jfSort jellyfin.Sort
switch sortOrder {
case AlbumSortRecentlyAdded:
case mediaprovider.AlbumSortRecentlyAdded:
jfSort.Field = jellyfin.SortByDateCreated
jfSort.Mode = jellyfin.SortDesc
case AlbumSortRandom:
case mediaprovider.AlbumSortRandom:
jfSort.Field = jellyfin.SortByRandom
case AlbumSortArtistAZ:
case mediaprovider.AlbumSortArtistAZ:
jfSort.Field = jellyfin.SortByArtist
jfSort.Mode = jellyfin.SortAsc
case AlbumSortTitleAZ:
case mediaprovider.AlbumSortTitleAZ:
jfSort.Field = jellyfin.SortByName
jfSort.Mode = jellyfin.SortAsc
case AlbumSortYearAscending:
case mediaprovider.AlbumSortYearAscending:
jfSort.Field = jellyfin.SortByYear
jfSort.Mode = jellyfin.SortAsc
case AlbumSortYearDescending:
case mediaprovider.AlbumSortYearDescending:
jfSort.Field = jellyfin.SortByYear
jfSort.Mode = jellyfin.SortDesc
}
Expand All @@ -64,7 +55,7 @@ func (j *jellyfinMediaProvider) IterateAlbums(sortOrder string, filter mediaprov
return sharedutil.MapSlice(al, toAlbum), nil
}

if sortOrder == AlbumSortRandom {
if sortOrder == mediaprovider.AlbumSortRandom {
determFetcher := func(offs, limit int) ([]*mediaprovider.Album, error) {
al, err := j.client.GetAlbums(jellyfin.QueryOpts{
Sort: jellyfin.Sort{Field: "SortName", Mode: jellyfin.SortAsc},
Expand Down
19 changes: 19 additions & 0 deletions backend/mediaprovider/mediaprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ import (
"github.com/deluan/sanitize"
)

const (
// set of all supported album sorts across all media providers
// these strings may be translated
AlbumSortRecentlyAdded string = "Recently Added"
AlbumSortRecentlyPlayed string = "Recently Played"
AlbumSortFrequentlyPlayed string = "Frequently Played"
AlbumSortRandom string = "Random"
AlbumSortTitleAZ string = "Title (A-Z)"
AlbumSortArtistAZ string = "Artist (A-Z)"
AlbumSortYearAscending string = "Year (ascending)"
AlbumSortYearDescending string = "Year (descending)"

// set of all supported artist sorts across all media providers
// these strings may be translated
ArtistSortAlbumCount string = "Album Count"
ArtistSortNameAZ string = "Name (A-Z)"
ArtistSortRandom string = "Random"
)

type MediaIterator[M any] interface {
Next() *M
}
Expand Down
45 changes: 17 additions & 28 deletions backend/mediaprovider/subsonic/albumiterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,16 @@ import (
"github.com/dweymouth/supersonic/sharedutil"
)

const (
AlbumSortRecentlyAdded string = "Recently Added"
AlbumSortRecentlyPlayed string = "Recently Played"
AlbumSortFrequentlyPlayed string = "Frequently Played"
AlbumSortRandom string = "Random"
AlbumSortTitleAZ string = "Title (A-Z)"
AlbumSortArtistAZ string = "Artist (A-Z)"
AlbumSortYearAscending string = "Year (ascending)"
AlbumSortYearDescending string = "Year (descending)"
)

func (s *subsonicMediaProvider) AlbumSortOrders() []string {
return []string{
AlbumSortRecentlyAdded,
AlbumSortRecentlyPlayed,
AlbumSortFrequentlyPlayed,
AlbumSortRandom,
AlbumSortTitleAZ,
AlbumSortArtistAZ,
AlbumSortYearAscending,
AlbumSortYearDescending,
mediaprovider.AlbumSortRecentlyAdded,
mediaprovider.AlbumSortRecentlyPlayed,
mediaprovider.AlbumSortFrequentlyPlayed,
mediaprovider.AlbumSortRandom,
mediaprovider.AlbumSortTitleAZ,
mediaprovider.AlbumSortArtistAZ,
mediaprovider.AlbumSortYearAscending,
mediaprovider.AlbumSortYearDescending,
}
}

Expand Down Expand Up @@ -86,28 +75,28 @@ func (s *subsonicMediaProvider) IterateAlbums(sortOrder string, filter mediaprov
return s.baseIterFromSimpleSortOrder("starred", modifiedFilter)
}
if sortOrder == "" {
sortOrder = AlbumSortRecentlyAdded // default
sortOrder = mediaprovider.AlbumSortRecentlyAdded // default
}
switch sortOrder {
case AlbumSortRecentlyAdded:
case mediaprovider.AlbumSortRecentlyAdded:
return s.baseIterFromSimpleSortOrder("newest", filter)
case AlbumSortRecentlyPlayed:
case mediaprovider.AlbumSortRecentlyPlayed:
return s.baseIterFromSimpleSortOrder("recent", filter)
case AlbumSortFrequentlyPlayed:
case mediaprovider.AlbumSortFrequentlyPlayed:
return s.baseIterFromSimpleSortOrder("frequent", filter)
case AlbumSortRandom:
case mediaprovider.AlbumSortRandom:
return s.newRandomIter(filter, s.prefetchCoverCB)
case AlbumSortTitleAZ:
case mediaprovider.AlbumSortTitleAZ:
return s.baseIterFromSimpleSortOrder("alphabeticalByName", filter)
case AlbumSortArtistAZ:
case mediaprovider.AlbumSortArtistAZ:
return s.baseIterFromSimpleSortOrder("alphabeticalByArtist", filter)
case AlbumSortYearAscending:
case mediaprovider.AlbumSortYearAscending:
fetchFn := func(offset, limit int) ([]*subsonic.AlbumID3, error) {
return s.client.GetAlbumList2("byYear",
map[string]string{"fromYear": "0", "toYear": "3000", "offset": strconv.Itoa(offset), "limit": strconv.Itoa(limit)})
}
return helpers.NewAlbumIterator(makeFetchFn(fetchFn), filter, s.prefetchCoverCB)
case AlbumSortYearDescending:
case mediaprovider.AlbumSortYearDescending:
fetchFn := func(offset, limit int) ([]*subsonic.AlbumID3, error) {
return s.client.GetAlbumList2("byYear",
map[string]string{"fromYear": "3000", "toYear": "0", "offset": strconv.Itoa(offset), "limit": strconv.Itoa(limit)})
Expand Down
20 changes: 7 additions & 13 deletions backend/mediaprovider/subsonic/artistiterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ import (
"github.com/dweymouth/supersonic/sharedutil"
)

const (
ArtistSortAlbumCount string = "Album Count"
ArtistSortNameAZ string = "Name (A-Z)"
ArtistSortRandom string = "Random"
)

func (s *subsonicMediaProvider) ArtistSortOrders() []string {
return []string{
ArtistSortAlbumCount,
ArtistSortNameAZ,
ArtistSortRandom,
mediaprovider.ArtistSortAlbumCount,
mediaprovider.ArtistSortNameAZ,
mediaprovider.ArtistSortRandom,
}
}

Expand All @@ -37,10 +31,10 @@ func filterArtistMatches(f mediaprovider.ArtistFilter, artist *subsonic.ArtistID

func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediaprovider.ArtistFilter) mediaprovider.ArtistIterator {
if sortOrder == "" {
sortOrder = ArtistSortNameAZ // default
sortOrder = mediaprovider.ArtistSortNameAZ // default
}
switch sortOrder {
case ArtistSortAlbumCount:
case mediaprovider.ArtistSortAlbumCount:
return s.baseArtistIterFromSimpleSortOrder(
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
slices.SortStableFunc(artists, func(a, b *subsonic.ArtistID3) int {
Expand All @@ -50,7 +44,7 @@ func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediapro
},
filter,
)
case ArtistSortNameAZ:
case mediaprovider.ArtistSortNameAZ:
return s.baseArtistIterFromSimpleSortOrder(
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
c := collate.New(language.English, collate.Loose)
Expand All @@ -61,7 +55,7 @@ func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediapro
},
filter,
)
case ArtistSortRandom:
case mediaprovider.ArtistSortRandom:
return s.baseArtistIterFromSimpleSortOrder(
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
newArtists := make([]*subsonic.ArtistID3, len(artists))
Expand Down
2 changes: 1 addition & 1 deletion backend/mediaprovider/subsonic/trackiterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (s *subsonicMediaProvider) IterateTracks(searchQuery string) mediaprovider.
return &allTracksIterator{
s: s,
albumIter: s.IterateAlbums(
AlbumSortArtistAZ,
mediaprovider.AlbumSortArtistAZ,
mediaprovider.NewAlbumFilter(mediaprovider.AlbumFilterOptions{}),
),
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace fyne.io/fyne/v2 v2.5.0 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240701152141-03bb69ca60ab
replace fyne.io/fyne/v2 v2.5.0 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240721175043-f7b0391c76a6
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ github.com/dweymouth/fyne-advanced-list v0.0.0-20240623145729-9c6b8f99bcfe h1:ow
github.com/dweymouth/fyne-advanced-list v0.0.0-20240623145729-9c6b8f99bcfe/go.mod h1:sbOhla4VcfFb4OjXiUFTLXMPTnhRUlVrDMhB8HtWR4o=
github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64 h1:RUIrnGY034rDMlcOui/daurwX5b+52KdUKhH9aXaDSg=
github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64/go.mod h1:3YrjFDHMlhCsSZ/OvmJCxWm9QHSgOVWZBxnraZz9Z7c=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240701152141-03bb69ca60ab h1:ShhYp3PTlbBGMo2Q2E2bmK9IlXuh0e1675VawRz6ps4=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240701152141-03bb69ca60ab/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240721175043-f7b0391c76a6 h1:4NuEVS2zgD14ptLoMU21j6Fd23Bjoject4LjfGnCPv0=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240721175043-f7b0391c76a6/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc=
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645 h1:KzqSaQwG3HsTZQlEtkp0BeUy9vmYZ0rq0B15qIPSiBs=
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645/go.mod h1:fcUagHBaQnt06GmBAllNE0J4O/7064zXRWdqnTTtVjI=
github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee h1:ZGyJ6wp7CAfT31BugypcF/TPKEy2RrGR9JFq1JOjOpY=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/lang"
)

func main() {
Expand Down Expand Up @@ -43,6 +44,7 @@ func main() {
os.Setenv("FYNE_SCALE", "1.1")
}

lang.AddTranslationsFS(res.Translations, "translations")
fyneApp := app.New()
fyneApp.SetIcon(res.ResAppicon256Png)

Expand Down
6 changes: 6 additions & 0 deletions res/translations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package res

import "embed"

//go:embed translations
var Translations embed.FS
Loading

0 comments on commit 8145fbd

Please sign in to comment.