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-25 21:26:54 +00:00
|
|
|
type commonLangs map[string]commonLang
|
|
|
|
|
|
|
|
type commonLang struct {
|
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
}
|
|
|
|
|
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-25 18:01:18 +00:00
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
Notifications langSection `json:"notifications"`
|
|
|
|
notificationsJSON string
|
2021-01-19 00:29:29 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-25 21:26:54 +00:00
|
|
|
type setupLangs map[string]setupLang
|
|
|
|
|
|
|
|
type setupLang struct {
|
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
StartPage langSection `json:"startPage"`
|
|
|
|
EndPage langSection `json:"endPage"`
|
2021-01-27 21:35:41 +00:00
|
|
|
General langSection `json:"general"`
|
2021-01-25 21:26:54 +00:00
|
|
|
Language langSection `json:"language"`
|
|
|
|
Login langSection `json:"login"`
|
|
|
|
JellyfinEmby langSection `json:"jellyfinEmby"`
|
2021-01-27 21:35:41 +00:00
|
|
|
Ombi langSection `json:"ombi"`
|
2021-01-25 21:26:54 +00:00
|
|
|
Email langSection `json:"email"`
|
|
|
|
Notifications langSection `json:"notifications"`
|
2021-01-26 22:57:29 +00:00
|
|
|
WelcomeEmails langSection `json:"welcomeEmails"`
|
2021-01-25 21:26:54 +00:00
|
|
|
PasswordResets langSection `json:"passwordResets"`
|
|
|
|
InviteEmails langSection `json:"inviteEmails"`
|
|
|
|
PasswordValidation langSection `json:"passwordValidation"`
|
|
|
|
HelpMessages langSection `json:"helpMessages"`
|
2021-01-26 22:57:29 +00:00
|
|
|
JSON string
|
2021-01-25 21:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ls *setupLangs) 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
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return chosenLang, opts
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|