2021-01-18 22:06:50 +00:00
|
|
|
package main
|
|
|
|
|
2021-01-21 18:57:32 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
2021-01-19 00:29:29 +00:00
|
|
|
|
2021-01-18 22:06:50 +00:00
|
|
|
type langMeta struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type quantityString struct {
|
|
|
|
Singular string `json:"singular"`
|
|
|
|
Plural string `json:"plural"`
|
|
|
|
}
|
|
|
|
|
2021-01-19 00:29:29 +00:00
|
|
|
type adminLangs map[string]adminLang
|
|
|
|
|
|
|
|
func (ls *adminLangs) getOptions(chosen string) (string, []string) {
|
|
|
|
opts := make([]string, len(*ls))
|
|
|
|
chosenLang := (*ls)[chosen].Meta.Name
|
|
|
|
i := 0
|
|
|
|
for _, lang := range *ls {
|
|
|
|
opts[i] = lang.Meta.Name
|
2021-01-21 14:16:03 +00:00
|
|
|
i++
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
|
|
|
return chosenLang, opts
|
|
|
|
}
|
|
|
|
|
2021-01-18 22:06:50 +00:00
|
|
|
type adminLang struct {
|
|
|
|
Meta langMeta `json:"meta"`
|
2021-01-19 00:29:29 +00:00
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
Notifications langSection `json:"notifications"`
|
2021-01-18 22:06:50 +00:00
|
|
|
QuantityStrings map[string]quantityString `json:"quantityStrings"`
|
2021-01-19 00:29:29 +00:00
|
|
|
JSON string
|
|
|
|
}
|
|
|
|
|
|
|
|
type formLangs map[string]formLang
|
|
|
|
|
|
|
|
func (ls *formLangs) getOptions(chosen string) (string, []string) {
|
|
|
|
opts := make([]string, len(*ls))
|
|
|
|
chosenLang := (*ls)[chosen].Meta.Name
|
|
|
|
i := 0
|
|
|
|
for _, lang := range *ls {
|
|
|
|
opts[i] = lang.Meta.Name
|
2021-01-21 14:16:03 +00:00
|
|
|
i++
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
|
|
|
return chosenLang, opts
|
2021-01-18 22:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type formLang struct {
|
2021-01-19 00:29:29 +00:00
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
ValidationStrings map[string]quantityString `json:"validationStrings"`
|
|
|
|
validationStringsJSON string
|
|
|
|
}
|
|
|
|
|
|
|
|
type emailLangs map[string]emailLang
|
|
|
|
|
|
|
|
func (ls *emailLangs) getOptions(chosen string) (string, []string) {
|
|
|
|
opts := make([]string, len(*ls))
|
|
|
|
chosenLang := (*ls)[chosen].Meta.Name
|
|
|
|
i := 0
|
|
|
|
for _, lang := range *ls {
|
|
|
|
opts[i] = lang.Meta.Name
|
2021-01-21 14:16:03 +00:00
|
|
|
i++
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
|
|
|
return chosenLang, opts
|
|
|
|
}
|
|
|
|
|
|
|
|
type emailLang struct {
|
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
UserCreated langSection `json:"userCreated"`
|
|
|
|
InviteExpiry langSection `json:"inviteExpiry"`
|
|
|
|
PasswordReset langSection `json:"passwordReset"`
|
|
|
|
UserDeleted langSection `json:"userDeleted"`
|
|
|
|
InviteEmail langSection `json:"inviteEmail"`
|
2021-01-24 15:19:58 +00:00
|
|
|
WelcomeEmail langSection `json:"welcomeEmail"`
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type langSection map[string]string
|
|
|
|
|
2021-01-21 18:57:32 +00:00
|
|
|
func (el langSection) format(field string, vals ...string) string {
|
2021-01-19 00:29:29 +00:00
|
|
|
text := el.get(field)
|
|
|
|
for _, val := range vals {
|
|
|
|
text = strings.Replace(text, "{n}", val, 1)
|
|
|
|
}
|
|
|
|
return text
|
|
|
|
}
|
|
|
|
|
2021-01-21 18:57:32 +00:00
|
|
|
func (el langSection) get(field string) string {
|
|
|
|
t, ok := el[field]
|
2021-01-19 00:29:29 +00:00
|
|
|
if !ok {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return t
|
2021-01-18 22:06:50 +00:00
|
|
|
}
|