diff --git a/html/form-base.html b/html/form-base.html index df49c4b..b702b4d 100644 --- a/html/form-base.html +++ b/html/form-base.html @@ -1,8 +1,8 @@ {{ define "form-base" }} diff --git a/html/form.html b/html/form.html index 26706d1..f8796e6 100644 --- a/html/form.html +++ b/html/form.html @@ -3,14 +3,14 @@ {{ template "header.html" . }} - {{ .lang.pageTitle }} + {{ .strings.pageTitle }}
@@ -27,34 +27,34 @@
- {{ .lang.createAccountHeader }} + {{ .strings.createAccountHeader }} {{ .helpMessage }}
- - + + - - + + - - + +
- {{ .lang.passwordRequirementsHeader }} + {{ .strings.passwordRequirementsHeader }}
    {{ range $key, $value := .requirements }}
  • @@ -70,9 +70,6 @@
- {{ template "form-base" . }} diff --git a/lang.go b/lang.go new file mode 100644 index 0000000..c5b7b90 --- /dev/null +++ b/lang.go @@ -0,0 +1,22 @@ +package main + +type langMeta struct { + Name string `json:"name"` +} + +type quantityString struct { + Singular string `json:"singular"` + Plural string `json:"plural"` +} + +type adminLang struct { + Meta langMeta `json:"meta"` + Strings map[string]string `json:"strings"` + Notifications map[string]string `json:"notifications"` + QuantityStrings map[string]quantityString `json:"quantityStrings"` +} + +type formLang struct { + Strings map[string]string `json:"strings"` + ValidationStrings map[string]quantityString `json:"validationStrings"` +} diff --git a/lang/form/en-us.json b/lang/form/en-us.json index fdebc18..a1f67da 100644 --- a/lang/form/en-us.json +++ b/lang/form/en-us.json @@ -14,28 +14,28 @@ "createAccountButton": "Create Account", "passwordRequirementsHeader": "Password Requirements", "successHeader": "Success!", - "successContinueButton": "Continue", - "validationStrings": { - "length": { - "singular": "Must have at least {n} character", - "plural": "Must have at 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" - } + "successContinueButton": "Continue" + }, + "validationStrings": { + "length": { + "singular": "Must have at least {n} character", + "plural": "Must have at 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/lang/form/fr-fr.json b/lang/form/fr-fr.json index 102148e..47f39c4 100644 --- a/lang/form/fr-fr.json +++ b/lang/form/fr-fr.json @@ -15,28 +15,28 @@ "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" - } + "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/lang/form/nl-nl.json b/lang/form/nl-nl.json index 96d9b9e..6843dab 100644 --- a/lang/form/nl-nl.json +++ b/lang/form/nl-nl.json @@ -14,28 +14,28 @@ "createAccountButton": "Maak account aan", "passwordRequirementsHeader": "Wachtwoordvereisten", "successHeader": "Succes!", - "successContinueButton": "Doorgaan", - "validationStrings": { - "length": { - "singular": "Moet ten minste {n} teken bevatten", - "plural": "Moet ten minste {n} tekens bevatten" - }, - "uppercase": { - "singular": "Moet ten minste {n} hoofdletter bevatten", - "plural": "Moet ten minste {n} hoofdletters bevatten" - }, - "lowercase": { - "singular": "Moet ten minste {n} kleine letter bevatten", - "plural": "Moet ten minste {n} kleine letters bevatten" - }, - "number": { - "singular": "Moet ten minste {n} cijfer bevatten", - "plural": "Moet ten minste {n} cijfers bevatten" - }, - "special": { - "singular": "Moet ten minste {n} bijzonder teken bevatten", - "plural": "Moet ten minste {n} bijzondere tekens bevatten" - } + "successContinueButton": "Doorgaan" + }, + "validationStrings": { + "length": { + "singular": "Moet ten minste {n} teken bevatten", + "plural": "Moet ten minste {n} tekens bevatten" + }, + "uppercase": { + "singular": "Moet ten minste {n} hoofdletter bevatten", + "plural": "Moet ten minste {n} hoofdletters bevatten" + }, + "lowercase": { + "singular": "Moet ten minste {n} kleine letter bevatten", + "plural": "Moet ten minste {n} kleine letters bevatten" + }, + "number": { + "singular": "Moet ten minste {n} cijfer bevatten", + "plural": "Moet ten minste {n} cijfers bevatten" + }, + "special": { + "singular": "Moet ten minste {n} bijzonder teken bevatten", + "plural": "Moet ten minste {n} bijzondere tekens bevatten" } } } diff --git a/models.go b/models.go index 8c2b5de..4a26e1a 100644 --- a/models.go +++ b/models.go @@ -147,7 +147,7 @@ type setting struct { } type section struct { - Meta meta `json:"meta"` + Meta langMeta `json:"meta"` Order []string `json:"order"` Settings map[string]setting `json:"settings"` } diff --git a/storage.go b/storage.go index f61c50c..4dcbe6c 100644 --- a/storage.go +++ b/storage.go @@ -23,13 +23,19 @@ type Storage struct { type EmailLang map[string]map[string]map[string]interface{} // Map of lang codes to email name to fields func (el *EmailLang) format(lang, email, field string, vals ...string) string { - text := (*el)[lang][email][field].(string) + text := el.get(lang, email, field) for _, val := range vals { text = strings.Replace(text, "{n}", val, 1) } return text } -func (el *EmailLang) get(lang, email, field string) string { return (*el)[lang][email][field].(string) } +func (el *EmailLang) get(lang, email, field string) string { + t, ok := (*el)[lang][email][field] + if !ok { + t = (*el)["en-us"][email][field] + } + return t.(string) +} type Lang struct { chosenFormLang string @@ -121,14 +127,12 @@ func (st *Storage) loadLang() error { return err } for index, lang := range form { - strings := lang["strings"].(map[string]interface{}) - validationStrings := strings["validationStrings"].(map[string]interface{}) + validationStrings := lang["validationStrings"].(map[string]interface{}) vS, err := json.Marshal(validationStrings) if err != nil { return err } - strings["validationStrings"] = string(vS) - lang["strings"] = strings + lang["validationStrings"] = string(vS) form[index] = lang } st.lang.Form = form diff --git a/views.go b/views.go index 6347ee6..77a07d4 100644 --- a/views.go +++ b/views.go @@ -84,18 +84,19 @@ func (app *appContext) InviteProxy(gc *gin.Context) { email = "" } gcHTML(gc, http.StatusOK, "form-loader.html", gin.H{ - "urlBase": app.URLBase, - "cssClass": app.cssClass, - "contactMessage": app.config.Section("ui").Key("contact_message").String(), - "helpMessage": app.config.Section("ui").Key("help_message").String(), - "successMessage": app.config.Section("ui").Key("success_message").String(), - "jfLink": app.config.Section("jellyfin").Key("public_server").String(), - "validate": app.config.Section("password_validation").Key("enabled").MustBool(false), - "requirements": app.validator.getCriteria(), - "email": email, - "username": !app.config.Section("email").Key("no_username").MustBool(false), - "lang": app.storage.lang.Form[lang]["strings"], - "code": code, + "urlBase": app.URLBase, + "cssClass": app.cssClass, + "contactMessage": app.config.Section("ui").Key("contact_message").String(), + "helpMessage": app.config.Section("ui").Key("help_message").String(), + "successMessage": app.config.Section("ui").Key("success_message").String(), + "jfLink": app.config.Section("jellyfin").Key("public_server").String(), + "validate": app.config.Section("password_validation").Key("enabled").MustBool(false), + "requirements": app.validator.getCriteria(), + "email": email, + "username": !app.config.Section("email").Key("no_username").MustBool(false), + "strings": app.storage.lang.Form[lang]["strings"], + "validationStrings": app.storage.lang.Form[lang]["validationStrings"], + "code": code, }) } else { gcHTML(gc, 404, "invalidCode.html", gin.H{