Expose language setting in settings dialog, fix some bugs
This commit is contained in:
@@ -52,7 +52,7 @@ func main() {
|
|||||||
return t.Name == myApp.Config.Application.Language
|
return t.Name == myApp.Config.Application.Language
|
||||||
})
|
})
|
||||||
success := false
|
success := false
|
||||||
if lIdx > 0 {
|
if lIdx >= 0 {
|
||||||
tr := res.TranslationsInfo[lIdx]
|
tr := res.TranslationsInfo[lIdx]
|
||||||
content, err := res.Translations.ReadFile("translations/" + tr.TranslationFileName)
|
content, err := res.Translations.ReadFile("translations/" + tr.TranslationFileName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -61,10 +61,14 @@ func main() {
|
|||||||
name := lang.SystemLocale().LanguageString()
|
name := lang.SystemLocale().LanguageString()
|
||||||
lang.AddTranslations(fyne.NewStaticResource(name+".json", content))
|
lang.AddTranslations(fyne.NewStaticResource(name+".json", content))
|
||||||
success = true
|
success = true
|
||||||
|
} else {
|
||||||
|
log.Printf("Error loading translation file %s: %s\n", tr.TranslationFileName, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !success {
|
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()
|
fyneApp := app.New()
|
||||||
|
|||||||
+2
-2
@@ -17,10 +17,10 @@ var TranslationsInfo = []TranslationInfo{
|
|||||||
{Name: "es", DisplayName: "Español", TranslationFileName: "es.json"},
|
{Name: "es", DisplayName: "Español", TranslationFileName: "es.json"},
|
||||||
{Name: "fr", DisplayName: "François", TranslationFileName: "fr.json"},
|
{Name: "fr", DisplayName: "François", TranslationFileName: "fr.json"},
|
||||||
{Name: "it", DisplayName: "Italiano", TranslationFileName: "it.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: "pl", DisplayName: "Polski", TranslationFileName: "pl.json"},
|
||||||
{Name: "pt_BR", DisplayName: "Português (BR)", TranslationFileName: "pt_BR.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: "zhHans", DisplayName: "中文", TranslationFileName: "zhHans.json"},
|
||||||
{Name: "zhHant", DisplayName: "中文 (trad.)", TranslationFileName: "zhHant.json"},
|
{Name: "zhHant", DisplayName: "中文 (trad.)", TranslationFileName: "zhHant.json"},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/dweymouth/supersonic/backend"
|
"github.com/dweymouth/supersonic/backend"
|
||||||
"github.com/dweymouth/supersonic/backend/player/mpv"
|
"github.com/dweymouth/supersonic/backend/player/mpv"
|
||||||
|
"github.com/dweymouth/supersonic/res"
|
||||||
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"
|
||||||
"github.com/dweymouth/supersonic/ui/widgets"
|
"github.com/dweymouth/supersonic/ui/widgets"
|
||||||
@@ -146,6 +147,28 @@ func (s *SettingsDialog) createGeneralTab(canSaveQueueToServer bool) *container.
|
|||||||
if startupPage.Selected == "" {
|
if startupPage.Selected == "" {
|
||||||
startupPage.SetSelectedIndex(0)
|
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"),
|
closeToTray := widget.NewCheckWithData(lang.L("Close to system tray"),
|
||||||
binding.BindBool(&s.config.Application.CloseToSystemTray))
|
binding.BindBool(&s.config.Application.CloseToSystemTray))
|
||||||
if !s.config.Application.EnableSystemTray {
|
if !s.config.Application.EnableSystemTray {
|
||||||
@@ -285,8 +308,9 @@ func (s *SettingsDialog) createGeneralTab(canSaveQueueToServer bool) *container.
|
|||||||
scrobbleEnabled.Checked = s.config.Scrobbling.Enabled
|
scrobbleEnabled.Checked = s.config.Scrobbling.Enabled
|
||||||
|
|
||||||
return container.NewTabItem(lang.L("General"), container.NewVBox(
|
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.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
|
themeFileSelect, // center
|
||||||
),
|
),
|
||||||
container.NewHBox(
|
container.NewHBox(
|
||||||
|
|||||||
Reference in New Issue
Block a user