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:
parent
26a1f30d32
commit
1aadd12006
@ -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>
|
||||||
|
@ -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
22
lang.go
Normal 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"`
|
||||||
|
}
|
@ -14,7 +14,8 @@
|
|||||||
"createAccountButton": "Create Account",
|
"createAccountButton": "Create Account",
|
||||||
"passwordRequirementsHeader": "Password Requirements",
|
"passwordRequirementsHeader": "Password Requirements",
|
||||||
"successHeader": "Success!",
|
"successHeader": "Success!",
|
||||||
"successContinueButton": "Continue",
|
"successContinueButton": "Continue"
|
||||||
|
},
|
||||||
"validationStrings": {
|
"validationStrings": {
|
||||||
"length": {
|
"length": {
|
||||||
"singular": "Must have at least {n} character",
|
"singular": "Must have at least {n} character",
|
||||||
@ -37,5 +38,4 @@
|
|||||||
"plural": "Must have at least {n} special characters"
|
"plural": "Must have at least {n} special characters"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
"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": {
|
"validationStrings": {
|
||||||
"length": {
|
"length": {
|
||||||
"singular": "Doit avoir au moins {n} caractère",
|
"singular": "Doit avoir au moins {n} caractère",
|
||||||
@ -38,5 +39,4 @@
|
|||||||
"plural": "Doit avoir au moins {n} caractères spéciaux"
|
"plural": "Doit avoir au moins {n} caractères spéciaux"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
"createAccountButton": "Maak account aan",
|
"createAccountButton": "Maak account aan",
|
||||||
"passwordRequirementsHeader": "Wachtwoordvereisten",
|
"passwordRequirementsHeader": "Wachtwoordvereisten",
|
||||||
"successHeader": "Succes!",
|
"successHeader": "Succes!",
|
||||||
"successContinueButton": "Doorgaan",
|
"successContinueButton": "Doorgaan"
|
||||||
|
},
|
||||||
"validationStrings": {
|
"validationStrings": {
|
||||||
"length": {
|
"length": {
|
||||||
"singular": "Moet ten minste {n} teken bevatten",
|
"singular": "Moet ten minste {n} teken bevatten",
|
||||||
@ -37,5 +38,4 @@
|
|||||||
"plural": "Moet ten minste {n} bijzondere tekens bevatten"
|
"plural": "Moet ten minste {n} bijzondere tekens bevatten"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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"`
|
||||||
}
|
}
|
||||||
|
16
storage.go
16
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
|
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
|
||||||
|
3
views.go
3
views.go
@ -94,7 +94,8 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
|
|||||||
"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"],
|
||||||
|
"validationStrings": app.storage.lang.Form[lang]["validationStrings"],
|
||||||
"code": code,
|
"code": code,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user