From 34c04ba9d99625e0e44c649c8379f6b3995237f4 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Tue, 17 Dec 2024 19:15:16 -0800 Subject: [PATCH] Expose language setting in settings dialog, fix some bugs --- main.go | 8 ++++++-- res/translations.go | 4 ++-- ui/dialogs/settingsdialog.go | 26 +++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 7da1c446..d41eedfc 100644 --- a/main.go +++ b/main.go @@ -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() diff --git a/res/translations.go b/res/translations.go index a2398e6c..3f9e87d8 100644 --- a/res/translations.go +++ b/res/translations.go @@ -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"}, } diff --git a/ui/dialogs/settingsdialog.go b/ui/dialogs/settingsdialog.go index 07e7b85e..ee97f97b 100644 --- a/ui/dialogs/settingsdialog.go +++ b/ui/dialogs/settingsdialog.go @@ -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(