Expose language setting in settings dialog, fix some bugs

This commit is contained in:
Drew Weymouth
2024-12-17 19:15:16 -08:00
parent dd3f5874c4
commit 34c04ba9d9
3 changed files with 33 additions and 5 deletions
+6 -2
View File
@@ -52,7 +52,7 @@ func main() {
return t.Name == myApp.Config.Application.Language
})
success := false
if lIdx > 0 {
if lIdx >= 0 {
tr := res.TranslationsInfo[lIdx]
content, err := res.Translations.ReadFile("translations/" + tr.TranslationFileName)
if err == nil {
@@ -61,10 +61,14 @@ func main() {
name := lang.SystemLocale().LanguageString()
lang.AddTranslations(fyne.NewStaticResource(name+".json", content))
success = true
} else {
log.Printf("Error loading translation file %s: %s\n", tr.TranslationFileName, err.Error())
}
}
if !success {
lang.AddTranslationsFS(res.Translations, "translations")
if err := lang.AddTranslationsFS(res.Translations, "translations"); err != nil {
log.Printf("Error loading translations: %s", err.Error())
}
}
fyneApp := app.New()
+2 -2
View File
@@ -17,10 +17,10 @@ var TranslationsInfo = []TranslationInfo{
{Name: "es", DisplayName: "Español", TranslationFileName: "es.json"},
{Name: "fr", DisplayName: "François", TranslationFileName: "fr.json"},
{Name: "it", DisplayName: "Italiano", TranslationFileName: "it.json"},
{Name: "ja", DisplayName: "日本語", TranslationFileName: "de.json"},
{Name: "ja", DisplayName: "日本語", TranslationFileName: "ja.json"},
{Name: "pl", DisplayName: "Polski", TranslationFileName: "pl.json"},
{Name: "pt_BR", DisplayName: "Português (BR)", TranslationFileName: "pt_BR.json"},
{Name: "ro", DisplayName: "Română", TranslationFileName: "ro"},
{Name: "ro", DisplayName: "Română", TranslationFileName: "ro.json"},
{Name: "zhHans", DisplayName: "中文", TranslationFileName: "zhHans.json"},
{Name: "zhHant", DisplayName: "中文 (trad.)", TranslationFileName: "zhHant.json"},
}
+25 -1
View File
@@ -12,6 +12,7 @@ import (
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/player/mpv"
"github.com/dweymouth/supersonic/res"
myTheme "github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util"
"github.com/dweymouth/supersonic/ui/widgets"
@@ -146,6 +147,28 @@ func (s *SettingsDialog) createGeneralTab(canSaveQueueToServer bool) *container.
if startupPage.Selected == "" {
startupPage.SetSelectedIndex(0)
}
languageList := make([]string, len(res.TranslationsInfo)+1)
languageList[0] = lang.L("Auto")
var langSelIndex int
for i, tr := range res.TranslationsInfo {
languageList[i+1] = tr.DisplayName
if tr.Name == s.config.Application.Language {
langSelIndex = i + 1
}
}
languageSelect := widget.NewSelect(languageList, nil)
languageSelect.SetSelectedIndex(langSelIndex)
languageSelect.OnChanged = func(_ string) {
lang := "auto"
if i := languageSelect.SelectedIndex(); i > 0 {
lang = res.TranslationsInfo[i-1].Name
}
s.config.Application.Language = lang
s.setRestartRequired()
}
closeToTray := widget.NewCheckWithData(lang.L("Close to system tray"),
binding.BindBool(&s.config.Application.CloseToSystemTray))
if !s.config.Application.EnableSystemTray {
@@ -285,8 +308,9 @@ func (s *SettingsDialog) createGeneralTab(canSaveQueueToServer bool) *container.
scrobbleEnabled.Checked = s.config.Scrobbling.Enabled
return container.NewTabItem(lang.L("General"), container.NewVBox(
container.NewHBox(widget.NewLabel(lang.L("Language")), languageSelect),
container.NewBorder(nil, nil, widget.NewLabel(lang.L("Theme")), /*left*/
container.NewHBox(widget.NewLabel("Mode"), themeModeSelect, util.NewHSpace(5)), // right
container.NewHBox(widget.NewLabel(lang.L("Mode")), themeModeSelect, util.NewHSpace(5)), // right
themeFileSelect, // center
),
container.NewHBox(