1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

move validationStrings out of strings in lang/form

This commit is contained in:
Harvey Tindall 2021-01-18 22:06:50 +00:00
parent 26a1f30d32
commit 1aadd12006
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
9 changed files with 128 additions and 104 deletions

View File

@ -1,8 +1,8 @@
{{ define "form-base" }} {{ define "form-base" }}
<script> <script>
window.usernameEnabled = {{ .username }}; window.usernameEnabled = {{ .username }};
window.validationStrings = JSON.parse({{ .lang.validationStrings }}); window.validationStrings = JSON.parse({{ .validationStrings }});
window.invalidPassword = "{{ .lang.reEnterPasswordInvalid }}"; window.invalidPassword = "{{ .strings.reEnterPasswordInvalid }}";
window.URLBase = "{{ .urlBase }}"; window.URLBase = "{{ .urlBase }}";
window.code = "{{ .code }}"; window.code = "{{ .code }}";
</script> </script>

View File

@ -3,14 +3,14 @@
<head> <head>
<link rel="stylesheet" type="text/css" href="css/base.css"> <link rel="stylesheet" type="text/css" href="css/base.css">
{{ template "header.html" . }} {{ template "header.html" . }}
<title>{{ .lang.pageTitle }}</title> <title>{{ .strings.pageTitle }}</title>
</head> </head>
<body class="max-w-full overflow-x-hidden section"> <body class="max-w-full overflow-x-hidden section">
<div id="modal-success" class="modal"> <div id="modal-success" class="modal">
<div class="modal-content card"> <div class="modal-content card">
<span class="heading mb-1">{{ .lang.successHeader }}</span> <span class="heading mb-1">{{ .strings.successHeader }}</span>
<p class="content mb-1">{{ .successMessage }}</p> <p class="content mb-1">{{ .successMessage }}</p>
<a class="button ~urge !normal full-width center supra submit" href="{{ .jfLink }}" id="create-success-button">{{ .lang.successContinueButton }}</a> <a class="button ~urge !normal full-width center supra submit" href="{{ .jfLink }}" id="create-success-button">{{ .strings.successContinueButton }}</a>
</div> </div>
</div> </div>
<div id="notification-box"></div> <div id="notification-box"></div>
@ -27,34 +27,34 @@
<div class="page-container"> <div class="page-container">
<div class="card ~neutral !low"> <div class="card ~neutral !low">
<div class="row baseline"> <div class="row baseline">
<span class="col heading">{{ .lang.createAccountHeader }}</span> <span class="col heading">{{ .strings.createAccountHeader }}</span>
<span class="col subheading"> {{ .helpMessage }}</span> <span class="col subheading"> {{ .helpMessage }}</span>
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<form class="card ~neutral !normal" id="form-create" href=""> <form class="card ~neutral !normal" id="form-create" href="">
<label class="label supra"> <label class="label supra">
{{ .lang.username }} {{ .strings.username }}
<input type="text" class="input ~neutral !high mt-half mb-1" placeholder="{{ .lang.username }}" id="create-username" aria-label="{{ .lang.username }}"> <input type="text" class="input ~neutral !high mt-half mb-1" placeholder="{{ .strings.username }}" id="create-username" aria-label="{{ .strings.username }}">
</label> </label>
<label class="label supra" for="create-email">{{ .lang.emailAddress }}</label> <label class="label supra" for="create-email">{{ .strings.emailAddress }}</label>
<input type="email" class="input ~neutral 1high mt-half mb-1" placeholder="{{ .lang.emailAddress }}" id="create-email" aria-label="{{ .lang.emailAddress }}" value="{{ .email }}"> <input type="email" class="input ~neutral 1high mt-half mb-1" placeholder="{{ .strings.emailAddress }}" id="create-email" aria-label="{{ .strings.emailAddress }}" value="{{ .email }}">
<label class="label supra" for="create-password">{{ .lang.password }}</label> <label class="label supra" for="create-password">{{ .strings.password }}</label>
<input type="password" class="input ~neutral 1high mt-half mb-1" placeholder="{{ .lang.password }}" id="create-password" aria-label="{{ .lang.password }}"> <input type="password" class="input ~neutral 1high mt-half mb-1" placeholder="{{ .strings.password }}" id="create-password" aria-label="{{ .strings.password }}">
<label class="label supra" for="create-reenter-password">{{ .lang.reEnterPassword }}</label> <label class="label supra" for="create-reenter-password">{{ .strings.reEnterPassword }}</label>
<input type="password" class="input ~neutral 1high mt-half mb-1" placeholder="{{ .lang.password }}" id="create-reenter-password" aria-label="{{ .lang.reEnterPassword }}"> <input type="password" class="input ~neutral 1high mt-half mb-1" placeholder="{{ .strings.password }}" id="create-reenter-password" aria-label="{{ .strings.reEnterPassword }}">
<label> <label>
<input type="submit" class="unfocused"> <input type="submit" class="unfocused">
<span class="button ~urge !normal full-width center supra submit">{{ .lang.createAccountButton }}</span> <span class="button ~urge !normal full-width center supra submit">{{ .strings.createAccountButton }}</span>
</label> </label>
</form> </form>
</div> </div>
<div class="col"> <div class="col">
<div class="card ~neutral !normal"> <div class="card ~neutral !normal">
<span class="label supra" for="inv-uses">{{ .lang.passwordRequirementsHeader }}</span> <span class="label supra" for="inv-uses">{{ .strings.passwordRequirementsHeader }}</span>
<ul> <ul>
{{ range $key, $value := .requirements }} {{ range $key, $value := .requirements }}
<li class="" id="requirement-{{ $key }}" min="{{ $value }}"> <li class="" id="requirement-{{ $key }}" min="{{ $value }}">
@ -70,9 +70,6 @@
</div> </div>
</div> </div>
</div> </div>
<script>
window.validationStrings = {{ .lang.validationStrings }};
</script>
{{ template "form-base" . }} {{ template "form-base" . }}
</body> </body>
</html> </html>

22
lang.go Normal file
View File

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

View File

@ -14,28 +14,28 @@
"createAccountButton": "Create Account", "createAccountButton": "Create Account",
"passwordRequirementsHeader": "Password Requirements", "passwordRequirementsHeader": "Password Requirements",
"successHeader": "Success!", "successHeader": "Success!",
"successContinueButton": "Continue", "successContinueButton": "Continue"
"validationStrings": { },
"length": { "validationStrings": {
"singular": "Must have at least {n} character", "length": {
"plural": "Must have at least {n} characters" "singular": "Must have at least {n} character",
}, "plural": "Must have at least {n} characters"
"uppercase": { },
"singular": "Must have at least {n} uppercase character", "uppercase": {
"plural": "Must have at least {n} uppercase characters" "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", "lowercase": {
"plural": "Must have at least {n} lowercase characters" "singular": "Must have at least {n} lowercase character",
}, "plural": "Must have at least {n} lowercase characters"
"number": { },
"singular": "Must have at least {n} number", "number": {
"plural": "Must have at least {n} numbers" "singular": "Must have at least {n} number",
}, "plural": "Must have at least {n} numbers"
"special": { },
"singular": "Must have at least {n} special character", "special": {
"plural": "Must have at least {n} special characters" "singular": "Must have at least {n} special character",
} "plural": "Must have at least {n} special characters"
} }
} }
} }

View File

@ -15,28 +15,28 @@
"createAccountButton": "Créer le compte", "createAccountButton": "Créer le compte",
"passwordRequirementsHeader": "Mot de passe requis", "passwordRequirementsHeader": "Mot de passe requis",
"successHeader": "Succes!", "successHeader": "Succes!",
"successContinueButton": "Continuer", "successContinueButton": "Continuer"
"validationStrings": { },
"length": { "validationStrings": {
"singular": "Doit avoir au moins {n} caractère", "length": {
"plural": "Doit avoir au moins {n} caractères" "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", "uppercase": {
"plural": "Must have at least {n} caractères majuscules" "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", "lowercase": {
"plural": "Doit avoir au moins {n} caractères minuscules" "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", "number": {
"plural": "Doit avoir au moins {n} nombres" "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", "special": {
"plural": "Doit avoir au moins {n} caractères spéciaux" "singular": "Doit avoir au moins {n} caractère spécial",
} "plural": "Doit avoir au moins {n} caractères spéciaux"
} }
} }
} }

View File

@ -14,28 +14,28 @@
"createAccountButton": "Maak account aan", "createAccountButton": "Maak account aan",
"passwordRequirementsHeader": "Wachtwoordvereisten", "passwordRequirementsHeader": "Wachtwoordvereisten",
"successHeader": "Succes!", "successHeader": "Succes!",
"successContinueButton": "Doorgaan", "successContinueButton": "Doorgaan"
"validationStrings": { },
"length": { "validationStrings": {
"singular": "Moet ten minste {n} teken bevatten", "length": {
"plural": "Moet ten minste {n} tekens bevatten" "singular": "Moet ten minste {n} teken bevatten",
}, "plural": "Moet ten minste {n} tekens bevatten"
"uppercase": { },
"singular": "Moet ten minste {n} hoofdletter bevatten", "uppercase": {
"plural": "Moet ten minste {n} hoofdletters bevatten" "singular": "Moet ten minste {n} hoofdletter bevatten",
}, "plural": "Moet ten minste {n} hoofdletters bevatten"
"lowercase": { },
"singular": "Moet ten minste {n} kleine letter bevatten", "lowercase": {
"plural": "Moet ten minste {n} kleine letters bevatten" "singular": "Moet ten minste {n} kleine letter bevatten",
}, "plural": "Moet ten minste {n} kleine letters bevatten"
"number": { },
"singular": "Moet ten minste {n} cijfer bevatten", "number": {
"plural": "Moet ten minste {n} cijfers bevatten" "singular": "Moet ten minste {n} cijfer bevatten",
}, "plural": "Moet ten minste {n} cijfers bevatten"
"special": { },
"singular": "Moet ten minste {n} bijzonder teken bevatten", "special": {
"plural": "Moet ten minste {n} bijzondere tekens bevatten" "singular": "Moet ten minste {n} bijzonder teken bevatten",
} "plural": "Moet ten minste {n} bijzondere tekens bevatten"
} }
} }
} }

View File

@ -147,7 +147,7 @@ type setting struct {
} }
type section struct { type section struct {
Meta meta `json:"meta"` Meta langMeta `json:"meta"`
Order []string `json:"order"` Order []string `json:"order"`
Settings map[string]setting `json:"settings"` Settings map[string]setting `json:"settings"`
} }

View File

@ -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 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 { 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 { for _, val := range vals {
text = strings.Replace(text, "{n}", val, 1) text = strings.Replace(text, "{n}", val, 1)
} }
return text 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 { type Lang struct {
chosenFormLang string chosenFormLang string
@ -121,14 +127,12 @@ func (st *Storage) loadLang() error {
return err return err
} }
for index, lang := range form { for index, lang := range form {
strings := lang["strings"].(map[string]interface{}) validationStrings := lang["validationStrings"].(map[string]interface{})
validationStrings := strings["validationStrings"].(map[string]interface{})
vS, err := json.Marshal(validationStrings) vS, err := json.Marshal(validationStrings)
if err != nil { if err != nil {
return err return err
} }
strings["validationStrings"] = string(vS) lang["validationStrings"] = string(vS)
lang["strings"] = strings
form[index] = lang form[index] = lang
} }
st.lang.Form = form st.lang.Form = form

View File

@ -84,18 +84,19 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
email = "" email = ""
} }
gcHTML(gc, http.StatusOK, "form-loader.html", gin.H{ gcHTML(gc, http.StatusOK, "form-loader.html", gin.H{
"urlBase": app.URLBase, "urlBase": app.URLBase,
"cssClass": app.cssClass, "cssClass": app.cssClass,
"contactMessage": app.config.Section("ui").Key("contact_message").String(), "contactMessage": app.config.Section("ui").Key("contact_message").String(),
"helpMessage": app.config.Section("ui").Key("help_message").String(), "helpMessage": app.config.Section("ui").Key("help_message").String(),
"successMessage": app.config.Section("ui").Key("success_message").String(), "successMessage": app.config.Section("ui").Key("success_message").String(),
"jfLink": app.config.Section("jellyfin").Key("public_server").String(), "jfLink": app.config.Section("jellyfin").Key("public_server").String(),
"validate": app.config.Section("password_validation").Key("enabled").MustBool(false), "validate": app.config.Section("password_validation").Key("enabled").MustBool(false),
"requirements": app.validator.getCriteria(), "requirements": app.validator.getCriteria(),
"email": email, "email": email,
"username": !app.config.Section("email").Key("no_username").MustBool(false), "username": !app.config.Section("email").Key("no_username").MustBool(false),
"lang": app.storage.lang.Form[lang]["strings"], "strings": app.storage.lang.Form[lang]["strings"],
"code": code, "validationStrings": app.storage.lang.Form[lang]["validationStrings"],
"code": code,
}) })
} else { } else {
gcHTML(gc, 404, "invalidCode.html", gin.H{ gcHTML(gc, 404, "invalidCode.html", gin.H{