diff --git a/api.go b/api.go index c619d4a..d8ea7d6 100644 --- a/api.go +++ b/api.go @@ -3,6 +3,8 @@ package main import ( "encoding/json" "fmt" + "io/ioutil" + "path/filepath" "strconv" "strings" "time" @@ -1060,6 +1062,22 @@ func (app *appContext) ApplySettings(gc *gin.Context) { func (app *appContext) GetConfig(gc *gin.Context) { app.info.Println("Config requested") resp := map[string]interface{}{} + langPath := filepath.Join(app.local_path, "lang", "form") + app.lang.langFiles, _ = ioutil.ReadDir(langPath) + app.lang.langOptions = make([]string, len(app.lang.langFiles)) + chosenLang := app.config.Section("ui").Key("language").MustString("en-us") + ".json" + for i, f := range app.lang.langFiles { + if f.Name() == chosenLang { + app.lang.chosenIndex = i + } + var langFile map[string]interface{} + file, _ := ioutil.ReadFile(filepath.Join(langPath, f.Name())) + json.Unmarshal(file, &langFile) + + if meta, ok := langFile["meta"]; ok { + app.lang.langOptions[i] = meta.(map[string]interface{})["name"].(string) + } + } for section, settings := range app.configBase { if section == "order" { resp[section] = settings.([]interface{}) @@ -1079,6 +1097,9 @@ func (app *appContext) GetConfig(gc *gin.Context) { } } else if dataType == "bool" { resp[section].(map[string]interface{})[key].(map[string]interface{})["value"] = configKey.MustBool(false) + } else if dataType == "select" && key == "language" { + resp[section].(map[string]interface{})[key].(map[string]interface{})["options"] = app.lang.langOptions + resp[section].(map[string]interface{})[key].(map[string]interface{})["value"] = app.lang.langOptions[app.lang.chosenIndex] } else { resp[section].(map[string]interface{})[key].(map[string]interface{})["value"] = configKey.String() } @@ -1087,6 +1108,7 @@ func (app *appContext) GetConfig(gc *gin.Context) { } } } + // resp["jellyfin"].(map[string]interface{})["language"].(map[string]interface{})["options"].([]string) gc.JSON(200, resp) } @@ -1109,7 +1131,16 @@ func (app *appContext) ModifyConfig(gc *gin.Context) { tempConfig.NewSection(section) } for setting, value := range settings.(map[string]interface{}) { - tempConfig.Section(section).Key(setting).SetValue(value.(string)) + if section == "ui" && setting == "language" { + for i, lang := range app.lang.langOptions { + if value.(string) == lang { + tempConfig.Section(section).Key(setting).SetValue(strings.Replace(app.lang.langFiles[i].Name(), ".json", "", 1)) + break + } + } + } else { + tempConfig.Section(section).Key(setting).SetValue(value.(string)) + } } } } diff --git a/data/lang/form/fr-fr.json b/data/lang/form/fr-fr.json new file mode 100644 index 0000000..ec423f3 --- /dev/null +++ b/data/lang/form/fr-fr.json @@ -0,0 +1,39 @@ +{ + "meta": { + "name": "Francais (FR)" + }, + "strings": { + "pageTitle": "Créer un compte Jellyfin", + "createAccountHeader": "Création du compte", + "accountDetails": "Détails", + "emailAddress": "Email", + "username": "Pseudo", + "password": "Mot de passe", + "createAccountButton": "Créer le compte", + "passwordRequirementsHeader": "Mot de passe requis", + "successHeader": "Succes!", + "successContinueButton": "Continuer", + "validationStrings": { + "length": { + "singular": "Doit avoir au moins {n} caractère", + "plural": "Doit avoir au moins {n} caractères" + }, + "uppercase": { + "singular": "Doit avoir au moins {n} caractère majuscule", + "plural": "Must have at least {n} caractères majuscules" + }, + "lowercase": { + "singular": "Doit avoir au moins {n} caractère minuscule", + "plural": "Doit avoir au moins {n} caractères minuscules" + }, + "number": { + "singular": "Doit avoir au moins {n} nombre", + "plural": "Doit avoir au moins {n} nombres" + }, + "special": { + "singular": "Doit avoir au moins {n} caractère spécial", + "plural": "Doit avoir au moins {n} caractères spéciaux" + } + } + } +} diff --git a/main.go b/main.go index 91758d1..79786ed 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,13 @@ type appContext struct { port int version string quit chan os.Signal + lang Languages +} + +type Languages struct { + langFiles []os.FileInfo // Language filenames + langOptions []string // Language names + chosenIndex int } func (app *appContext) loadHTML(router *gin.Engine) { diff --git a/views.go b/views.go index 8b5b495..30814ae 100644 --- a/views.go +++ b/views.go @@ -1,8 +1,6 @@ package main import ( - "encoding/json" - "fmt" "net/http" "strings" @@ -51,9 +49,6 @@ func (app *appContext) InviteProxy(gc *gin.Context) { }, "lang": app.storage.lang.Form["strings"], }) - l, _ := json.MarshalIndent(app.storage.lang.Form, "", " ") - fmt.Println(app.storage.lang.Form["strings"].(map[string]interface{})["validationStrings"].(string)) - fmt.Printf("%s\n", l) } else { gc.HTML(404, "invalidCode.html", gin.H{ "bs5": app.config.Section("ui").Key("bs5").MustBool(false),