localize list of startup pages in Settings

This commit is contained in:
Drew Weymouth
2024-07-24 07:55:43 -07:00
parent 26c3bd8012
commit ff6a204284
4 changed files with 17 additions and 9 deletions
+1 -3
View File
@@ -8,7 +8,6 @@ import (
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/dweymouth/supersonic/backend" "github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider" "github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/sharedutil"
"github.com/dweymouth/supersonic/ui/controller" "github.com/dweymouth/supersonic/ui/controller"
myTheme "github.com/dweymouth/supersonic/ui/theme" myTheme "github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util" "github.com/dweymouth/supersonic/ui/util"
@@ -58,8 +57,7 @@ func (a *albumsPageAdapter) SortOrders() ([]string, int) {
sortOrder = 0 sortOrder = 0
} }
translatedOrders := sharedutil.MapSlice(orders, func(s string) string { return lang.L(s) }) return util.LocalizeSlice(orders), sortOrder
return translatedOrders, sortOrder
} }
func (a *albumsPageAdapter) SaveSortOrder(orderIdx int) { func (a *albumsPageAdapter) SaveSortOrder(orderIdx int) {
+1 -3
View File
@@ -8,7 +8,6 @@ import (
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/dweymouth/supersonic/backend" "github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider" "github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/sharedutil"
"github.com/dweymouth/supersonic/ui/controller" "github.com/dweymouth/supersonic/ui/controller"
myTheme "github.com/dweymouth/supersonic/ui/theme" myTheme "github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util" "github.com/dweymouth/supersonic/ui/util"
@@ -54,8 +53,7 @@ func (a *artistsPageAdapter) SortOrders() ([]string, int) {
sortOrder = 0 sortOrder = 0
} }
translatedOrders := sharedutil.MapSlice(orders, func(s string) string { return lang.L(s) }) return util.LocalizeSlice(orders), sortOrder
return translatedOrders, sortOrder
} }
func (a *artistsPageAdapter) SaveSortOrder(orderIdx int) { func (a *artistsPageAdapter) SaveSortOrder(orderIdx int) {
+10 -3
View File
@@ -4,6 +4,7 @@ import (
"errors" "errors"
"math" "math"
"os" "os"
"slices"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -132,10 +133,16 @@ func (s *SettingsDialog) createGeneralTab(canSaveQueueToServer bool) *container.
themeModeSelect.SetSelectedIndex(0) themeModeSelect.SetSelectedIndex(0)
} }
startupPage := widget.NewSelect(backend.SupportedStartupPages, func(choice string) { pages := util.LocalizeSlice(backend.SupportedStartupPages)
s.config.Application.StartupPage = choice var startupPage *widget.Select
startupPage = widget.NewSelect(pages, func(_ string) {
s.config.Application.StartupPage = backend.SupportedStartupPages[startupPage.SelectedIndex()]
}) })
startupPage.SetSelected(s.config.Application.StartupPage) initialIdx := slices.Index(backend.SupportedStartupPages, s.config.Application.StartupPage)
if initialIdx < 0 {
initialIdx = 0
}
startupPage.SetSelectedIndex(initialIdx)
if startupPage.Selected == "" { if startupPage.Selected == "" {
startupPage.SetSelectedIndex(0) startupPage.SetSelectedIndex(0)
} }
+5
View File
@@ -18,6 +18,7 @@ import (
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/dweymouth/supersonic/backend/mediaprovider" "github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/res" "github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/sharedutil"
myTheme "github.com/dweymouth/supersonic/ui/theme" myTheme "github.com/dweymouth/supersonic/ui/theme"
"golang.org/x/net/html" "golang.org/x/net/html"
) )
@@ -264,6 +265,10 @@ func SaveWindowSize(w fyne.Window, wPtr, hPtr *int) {
*hPtr = int(math.RoundToEven(float64(w.Canvas().Size().Height))) *hPtr = int(math.RoundToEven(float64(w.Canvas().Size().Height)))
} }
func LocalizeSlice(s []string) []string {
return sharedutil.MapSlice(s, func(s string) string { return lang.L(s) })
}
type HSpace struct { type HSpace struct {
widget.BaseWidget widget.BaseWidget