From 2d2727f7e8bf07b241d3b87fc1462ea6374017ab Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 12 Jan 2021 23:37:22 +0000 Subject: [PATCH] separate options for form and admin language --- api.go | 46 +++++++++++++++++++++++++++-------------- config.go | 11 ++++++++-- config/config-base.json | 15 ++++++++++++-- views.go | 4 ++-- 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/api.go b/api.go index ffcd5e9..ab7b7b7 100644 --- a/api.go +++ b/api.go @@ -1085,17 +1085,25 @@ func (app *appContext) GetConfig(gc *gin.Context) { app.info.Println("Config requested") resp := app.configBase // Load language options - langOptions := make([]string, len(app.storage.lang.Form)) - chosenLang := app.config.Section("ui").Key("language").MustString("en-us") - chosenLangName := app.storage.lang.Form[chosenLang]["meta"].(map[string]interface{})["name"].(string) - i := 0 - for _, lang := range app.storage.lang.Form { - langOptions[i] = lang["meta"].(map[string]interface{})["name"].(string) - i++ - } - l := resp.Sections["ui"].Settings["language"] - l.Options = langOptions - l.Value = chosenLangName + loadLangs := func(langs *map[string]map[string]interface{}, settingsKey string) (string, []string) { + langOptions := make([]string, len(*langs)) + chosenLang := app.config.Section("ui").Key("language-" + settingsKey).MustString("en-us") + chosenLangName := (*langs)[chosenLang]["meta"].(map[string]interface{})["name"].(string) + i := 0 + for _, lang := range *langs { + langOptions[i] = lang["meta"].(map[string]interface{})["name"].(string) + i++ + } + return chosenLangName, langOptions + } + formChosen, formOptions := loadLangs(&app.storage.lang.Form, "form") + fl := resp.Sections["ui"].Settings["language-form"] + fl.Options = formOptions + fl.Value = formChosen + adminChosen, adminOptions := loadLangs(&app.storage.lang.Admin, "admin") + al := resp.Sections["ui"].Settings["language-admin"] + al.Options = adminOptions + al.Value = adminChosen for sectName, section := range resp.Sections { for settingName, setting := range section.Settings { val := app.config.Section(sectName).Key(settingName) @@ -1111,11 +1119,12 @@ func (app *appContext) GetConfig(gc *gin.Context) { resp.Sections[sectName].Settings[settingName] = s } } - resp.Sections["ui"].Settings["language"] = l + resp.Sections["ui"].Settings["language-form"] = fl + resp.Sections["ui"].Settings["language-admin"] = al t := resp.Sections["jellyfin"].Settings["type"] opts := make([]string, len(serverTypes)) - i = 0 + i := 0 for _, v := range serverTypes { opts[i] = v i++ @@ -1146,10 +1155,17 @@ func (app *appContext) ModifyConfig(gc *gin.Context) { tempConfig.NewSection(section) } for setting, value := range settings.(map[string]interface{}) { - if section == "ui" && setting == "language" { + if section == "ui" && setting == "language-form" { for key, lang := range app.storage.lang.Form { if lang["meta"].(map[string]interface{})["name"].(string) == value.(string) { - tempConfig.Section("ui").Key("language").SetValue(key) + tempConfig.Section("ui").Key("language-form").SetValue(key) + break + } + } + } else if section == "ui" && setting == "language-admin" { + for key, lang := range app.storage.lang.Admin { + if lang["meta"].(map[string]interface{})["name"].(string) == value.(string) { + tempConfig.Section("ui").Key("language-admin").SetValue(key) break } } diff --git a/config.go b/config.go index 347bed4..247180e 100644 --- a/config.go +++ b/config.go @@ -84,8 +84,15 @@ func (app *appContext) loadConfig() error { substituteStrings = app.config.Section("jellyfin").Key("substitute_jellyfin_strings").MustString("") - app.storage.lang.chosenFormLang = app.config.Section("ui").Key("language").MustString("en-us") - app.storage.lang.chosenFormLang = app.config.Section("ui").Key("language").MustString("en-us") + oldFormLang := app.config.Section("ui").Key("language").MustString("") + if oldFormLang != "" { + app.storage.lang.chosenFormLang = oldFormLang + } + newFormLang := app.config.Section("ui").Key("language-form").MustString("") + if newFormLang != "" { + app.storage.lang.chosenFormLang = newFormLang + } + app.storage.lang.chosenAdminLang = app.config.Section("ui").Key("language-admin").MustString("en-us") return nil } diff --git a/config/config-base.json b/config/config-base.json index d32796c..382ac8f 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -84,7 +84,7 @@ "description": "Settings related to the UI and program functionality." }, "settings": { - "language": { + "language-form": { "name": "Default Form Language", "required": false, "requires_restart": true, @@ -93,7 +93,18 @@ "en-us" ], "value": "en-US", - "description": "Default UI Language. Currently only implemented for account creation form. Submit a PR on github if you'd like to translate." + "description": "Default Account Form Language. Submit a PR on github if you'd like to translate." + }, + "language-admin": { + "name": "Default Admin Language", + "required": false, + "requires_restart": true, + "type": "select", + "options": [ + "en-us" + ], + "value": "en-US", + "description": "Default Admin page Language. Settings has not been translated. Submit a PR on github if you'd like to translate." }, "theme": { "name": "Default Look", diff --git a/views.go b/views.go index f3aea03..d3939a8 100644 --- a/views.go +++ b/views.go @@ -15,9 +15,9 @@ func gcHTML(gc *gin.Context, code int, file string, templ gin.H) { func (app *appContext) AdminPage(gc *gin.Context) { lang := gc.Query("lang") if lang == "" { - lang = app.storage.lang.chosenFormLang + lang = app.storage.lang.chosenAdminLang } else if _, ok := app.storage.lang.Form[lang]; !ok { - lang = app.storage.lang.chosenFormLang + lang = app.storage.lang.chosenAdminLang } emailEnabled, _ := app.config.Section("invite_emails").Key("enabled").Bool() notificationsEnabled, _ := app.config.Section("notifications").Key("enabled").Bool()