move validationStrings out of strings in lang/form

pull/61/head
Harvey Tindall 4 years ago
parent 26a1f30d32
commit 1aadd12006
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

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

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

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

@ -14,7 +14,8 @@
"createAccountButton": "Create Account",
"passwordRequirementsHeader": "Password Requirements",
"successHeader": "Success!",
"successContinueButton": "Continue",
"successContinueButton": "Continue"
},
"validationStrings": {
"length": {
"singular": "Must have at least {n} character",
@ -37,5 +38,4 @@
"plural": "Must have at least {n} special characters"
}
}
}
}

@ -15,7 +15,8 @@
"createAccountButton": "Créer le compte",
"passwordRequirementsHeader": "Mot de passe requis",
"successHeader": "Succes!",
"successContinueButton": "Continuer",
"successContinueButton": "Continuer"
},
"validationStrings": {
"length": {
"singular": "Doit avoir au moins {n} caractère",
@ -38,5 +39,4 @@
"plural": "Doit avoir au moins {n} caractères spéciaux"
}
}
}
}

@ -14,7 +14,8 @@
"createAccountButton": "Maak account aan",
"passwordRequirementsHeader": "Wachtwoordvereisten",
"successHeader": "Succes!",
"successContinueButton": "Doorgaan",
"successContinueButton": "Doorgaan"
},
"validationStrings": {
"length": {
"singular": "Moet ten minste {n} teken bevatten",
@ -37,5 +38,4 @@
"plural": "Moet ten minste {n} bijzondere tekens bevatten"
}
}
}
}

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

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

@ -94,7 +94,8 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
"requirements": app.validator.getCriteria(),
"email": email,
"username": !app.config.Section("email").Key("no_username").MustBool(false),
"lang": app.storage.lang.Form[lang]["strings"],
"strings": app.storage.lang.Form[lang]["strings"],
"validationStrings": app.storage.lang.Form[lang]["validationStrings"],
"code": code,
})
} else {

Loading…
Cancel
Save