diff --git a/config/config-base.json b/config/config-base.json index a143a0e..c2341fd 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -49,6 +49,17 @@ "name": "General", "description": "Settings related to the UI and program functionality." }, + "language": { + "name": "Language", + "required": false, + "requires_restart": true, + "type": "select", + "options": [ + "en-us" + ], + "value": "en-US", + "description": "UI Language. Currently only implemented for account creation form. Submit a PR on github if you'd like to translate." + }, "theme": { "name": "Default Look", "required": false, diff --git a/data/lang/form/en-us.json b/data/lang/form/en-us.json new file mode 100644 index 0000000..1d0ab47 --- /dev/null +++ b/data/lang/form/en-us.json @@ -0,0 +1,39 @@ +{ + "meta": { + "name": "English (US)" + }, + "strings": { + "pageTitle": "Create Jellyfin Account", + "createAccountHeader": "Create Account", + "accountDetails": "Details", + "emailAddress": "Email", + "username": "Username", + "password": "Password", + "createAccountButton": "Create Account", + "passwordRequirementsHeader": "Password Requirements", + "successHeader": "Success!", + "successContinueButton": "Continue", + "validationStrings": { + "length": { + "singular": "Must have at least {n} character", + "plural": "Must have a least {n} characters" + }, + "uppercase": { + "singular": "Must have at least {n} uppercase character", + "plural": "Must have at least {n} uppercase characters" + }, + "lowercase": { + "singular": "Must have at least {n} lowercase character", + "plural": "Must have at least {n} lowercase characters" + }, + "number": { + "singular": "Must have at least {n} number", + "plural": "Must have at least {n} numbers" + }, + "special": { + "singular": "Must have at least {n} special character", + "plural": "Must have at least {n} special characters" + } + } + } +} diff --git a/data/templates/form-base.html b/data/templates/form-base.html index 087ad69..5569535 100644 --- a/data/templates/form-base.html +++ b/data/templates/form-base.html @@ -1,7 +1,8 @@ {{ define "form-base" }} {{ end }} diff --git a/data/templates/form.html b/data/templates/form.html index c1e87fe..1b2ed3b 100644 --- a/data/templates/form.html +++ b/data/templates/form.html @@ -41,27 +41,27 @@ margin-bottom: 5%; } - Create Jellyfin Account + {{ .lang.pageTitle }}

- Create Account + {{ .lang.createAccountHeader }}

{{ .helpMessage }}

{{ .contactMessage }}

@@ -69,26 +69,26 @@
-
Details
+
{{ .lang.accountDetails }}
- - + +
{{ if .settings.username }}
- - + +
{{ end }}
- - + +
@@ -98,7 +98,7 @@ {{ if .validate }}
-
Password Requirements
+
{{ .lang.passwordRequirementsHeader }}
    {{ range $key, $value := .requirements }} @@ -114,31 +114,10 @@
- - {{ template "form-base" .settings }} + {{ template "form-base" . }} diff --git a/main.go b/main.go index 353cca0..63dbf37 100644 --- a/main.go +++ b/main.go @@ -263,6 +263,12 @@ func start(asDaemon, firstCall bool) { if app.loadConfig() != nil { app.err.Fatalf("Failed to load config file \"%s\"", app.config_path) } + lang := app.config.Section("ui").Key("language").MustString("en-us") + app.storage.lang.FormPath = filepath.Join(app.local_path, "lang", "form", lang+".json") + if _, err := os.Stat(app.storage.lang.FormPath); os.IsNotExist(err) { + app.storage.lang.FormPath = filepath.Join(app.local_path, "lang", "form", "en-us.json") + } + app.storage.loadLang() app.version = app.config.Section("jellyfin").Key("version").String() // read from config... debugMode = app.config.Section("ui").Key("debug").MustBool(false) diff --git a/ombi.go b/ombi.go index c5b80b3..00067df 100644 --- a/ombi.go +++ b/ombi.go @@ -37,7 +37,7 @@ func newOmbi(server, key string, noFail bool) *Ombi { } } -// does a GET and returns the response as an io.reader. +// does a GET and returns the response as a string. func (ombi *Ombi) _getJSON(url string, params map[string]string) (string, int, error) { if ombi.key == "" { return "", 401, fmt.Errorf("No API key provided") diff --git a/storage.go b/storage.go index f03671f..becda9a 100644 --- a/storage.go +++ b/storage.go @@ -14,6 +14,12 @@ type Storage struct { profiles map[string]Profile defaultProfile string emails, policy, configuration, displayprefs, ombi_template map[string]interface{} + lang Lang +} + +type Lang struct { + FormPath string + Form map[string]interface{} } // timePattern: %Y-%m-%dT%H:%M:%S.%f @@ -49,6 +55,22 @@ func (st *Storage) storeInvites() error { return storeJSON(st.invite_path, st.invites) } +func (st *Storage) loadLang() error { + err := loadJSON(st.lang.FormPath, &st.lang.Form) + if err != nil { + return err + } + strings := st.lang.Form["strings"].(map[string]interface{}) + validationStrings := strings["validationStrings"].(map[string]interface{}) + vS, err := json.Marshal(validationStrings) + if err != nil { + return err + } + strings["validationStrings"] = string(vS) + st.lang.Form["strings"] = strings + return nil +} + func (st *Storage) loadEmails() error { return loadJSON(st.emails_path, &st.emails) } diff --git a/views.go b/views.go index e60156f..8b5b495 100644 --- a/views.go +++ b/views.go @@ -1,6 +1,8 @@ package main import ( + "encoding/json" + "fmt" "net/http" "strings" @@ -47,7 +49,11 @@ func (app *appContext) InviteProxy(gc *gin.Context) { "bs5": app.config.Section("ui").Key("bs5").MustBool(false), "username": !app.config.Section("email").Key("no_username").MustBool(false), }, + "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),