Skip to content

Commit

Permalink
add french, fix language selector in settings
Browse files Browse the repository at this point in the history
note: custom language files can now be added in data/lang/form and will be
listed in settings.
  • Loading branch information
hrfee committed Nov 3, 2020
1 parent 8e45ecb commit 493f10f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
33 changes: 32 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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{})
Expand All @@ -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()
}
Expand All @@ -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)
}

Expand All @@ -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))
}
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions data/lang/form/fr-fr.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions views.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"encoding/json"
"fmt"
"net/http"
"strings"

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 493f10f

Please sign in to comment.