Skip to content

Commit

Permalink
Expose language setting in settings dialog, fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Dec 18, 2024
1 parent dd3f587 commit 34c04ba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions res/translations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
26 changes: 25 additions & 1 deletion ui/dialogs/settingsdialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 34c04ba

Please sign in to comment.