1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-23 01:20:11 +00:00

add french, fix language selector in settings

note: custom language files can now be added in data/lang/form and will be
listed in settings.
This commit is contained in:
Harvey Tindall 2020-11-03 21:11:43 +00:00
parent 8e45ecb214
commit 493f10fa36
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
4 changed files with 78 additions and 6 deletions

31
api.go
View File

@ -3,6 +3,8 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -1060,6 +1062,22 @@ func (app *appContext) ApplySettings(gc *gin.Context) {
func (app *appContext) GetConfig(gc *gin.Context) { func (app *appContext) GetConfig(gc *gin.Context) {
app.info.Println("Config requested") app.info.Println("Config requested")
resp := map[string]interface{}{} 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 { for section, settings := range app.configBase {
if section == "order" { if section == "order" {
resp[section] = settings.([]interface{}) resp[section] = settings.([]interface{})
@ -1079,6 +1097,9 @@ func (app *appContext) GetConfig(gc *gin.Context) {
} }
} else if dataType == "bool" { } else if dataType == "bool" {
resp[section].(map[string]interface{})[key].(map[string]interface{})["value"] = configKey.MustBool(false) 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 { } else {
resp[section].(map[string]interface{})[key].(map[string]interface{})["value"] = configKey.String() 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) gc.JSON(200, resp)
} }
@ -1109,10 +1131,19 @@ func (app *appContext) ModifyConfig(gc *gin.Context) {
tempConfig.NewSection(section) tempConfig.NewSection(section)
} }
for setting, value := range settings.(map[string]interface{}) { for setting, value := range settings.(map[string]interface{}) {
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)) tempConfig.Section(section).Key(setting).SetValue(value.(string))
} }
} }
} }
}
tempConfig.SaveTo(app.config_path) tempConfig.SaveTo(app.config_path)
app.debug.Println("Config saved") app.debug.Println("Config saved")
gc.JSON(200, map[string]bool{"success": true}) gc.JSON(200, map[string]bool{"success": true})

39
data/lang/form/fr-fr.json Normal file
View File

@ -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"
}
}
}
}

View File

@ -67,6 +67,13 @@ type appContext struct {
port int port int
version string version string
quit chan os.Signal 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) { func (app *appContext) loadHTML(router *gin.Engine) {

View File

@ -1,8 +1,6 @@
package main package main
import ( import (
"encoding/json"
"fmt"
"net/http" "net/http"
"strings" "strings"
@ -51,9 +49,6 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
}, },
"lang": app.storage.lang.Form["strings"], "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 { } else {
gc.HTML(404, "invalidCode.html", gin.H{ gc.HTML(404, "invalidCode.html", gin.H{
"bs5": app.config.Section("ui").Key("bs5").MustBool(false), "bs5": app.config.Section("ui").Key("bs5").MustBool(false),