add ability to configure language in config file
This commit is contained in:
+4
-2
@@ -48,7 +48,8 @@ type AppConfig struct {
|
|||||||
ShowTrackChangeNotification bool
|
ShowTrackChangeNotification bool
|
||||||
EnableLrcLib bool
|
EnableLrcLib bool
|
||||||
SkipSSLVerify bool
|
SkipSSLVerify bool
|
||||||
EnqueueBatchSize int
|
EnqueueBatchSize int
|
||||||
|
Language string
|
||||||
|
|
||||||
// Experimental - may be removed in future
|
// Experimental - may be removed in future
|
||||||
FontNormalTTF string
|
FontNormalTTF string
|
||||||
@@ -174,7 +175,8 @@ func DefaultConfig(appVersionTag string) *Config {
|
|||||||
ShowTrackChangeNotification: false,
|
ShowTrackChangeNotification: false,
|
||||||
EnableLrcLib: true,
|
EnableLrcLib: true,
|
||||||
SkipSSLVerify: false,
|
SkipSSLVerify: false,
|
||||||
EnqueueBatchSize: 100,
|
EnqueueBatchSize: 100,
|
||||||
|
Language: "auto",
|
||||||
},
|
},
|
||||||
AlbumPage: AlbumPageConfig{
|
AlbumPage: AlbumPageConfig{
|
||||||
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"},
|
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"},
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -46,7 +47,26 @@ func main() {
|
|||||||
os.Setenv("FYNE_SCALE", "1.1")
|
os.Setenv("FYNE_SCALE", "1.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
lang.AddTranslationsFS(res.Translations, "translations")
|
// load configured app language, or all otherwise
|
||||||
|
lIdx := slices.IndexFunc(res.TranslationsInfo, func(t res.TranslationInfo) bool {
|
||||||
|
return t.Name == myApp.Config.Application.Language
|
||||||
|
})
|
||||||
|
success := false
|
||||||
|
if lIdx > 0 {
|
||||||
|
tr := res.TranslationsInfo[lIdx]
|
||||||
|
content, err := res.Translations.ReadFile("translations/" + tr.TranslationFileName)
|
||||||
|
if err == nil {
|
||||||
|
// "trick" Fyne into loading translations for configured language
|
||||||
|
// by pretending it's the translation for the system locale
|
||||||
|
name := lang.SystemLocale().LanguageString()
|
||||||
|
lang.AddTranslations(fyne.NewStaticResource(name+".json", content))
|
||||||
|
success = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !success {
|
||||||
|
lang.AddTranslationsFS(res.Translations, "translations")
|
||||||
|
}
|
||||||
|
|
||||||
fyneApp := app.New()
|
fyneApp := app.New()
|
||||||
fyneApp.SetIcon(res.ResAppicon256Png)
|
fyneApp.SetIcon(res.ResAppicon256Png)
|
||||||
|
|
||||||
|
|||||||
@@ -4,3 +4,23 @@ import "embed"
|
|||||||
|
|
||||||
//go:embed translations
|
//go:embed translations
|
||||||
var Translations embed.FS
|
var Translations embed.FS
|
||||||
|
|
||||||
|
type TranslationInfo struct {
|
||||||
|
Name string
|
||||||
|
DisplayName string
|
||||||
|
TranslationFileName string
|
||||||
|
}
|
||||||
|
|
||||||
|
var TranslationsInfo = []TranslationInfo{
|
||||||
|
{Name: "de", DisplayName: "Deutsch", TranslationFileName: "de.json"},
|
||||||
|
{Name: "en", DisplayName: "English", TranslationFileName: "en.json"},
|
||||||
|
{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: "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: "zhHans", DisplayName: "中文", TranslationFileName: "zhHans.json"},
|
||||||
|
{Name: "zhHant", DisplayName: "中文 (trad.)", TranslationFileName: "zhHant.json"},
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user