2021-01-18 22:06:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
type langMeta struct {
|
|
|
|
Name string `json:"name"`
|
2021-04-13 17:34:13 +00:00
|
|
|
// Language to fall back on if strings are missing. Defaults to en-us.
|
|
|
|
Fallback string `json:"fallback,omitempty"`
|
2021-01-18 22:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type quantityString struct {
|
|
|
|
Singular string `json:"singular"`
|
|
|
|
Plural string `json:"plural"`
|
|
|
|
}
|
|
|
|
|
2021-01-19 00:29:29 +00:00
|
|
|
type adminLangs map[string]adminLang
|
|
|
|
|
2021-01-31 18:50:04 +00:00
|
|
|
func (ls *adminLangs) getOptions() [][2]string {
|
|
|
|
opts := make([][2]string, len(*ls))
|
2021-01-19 00:29:29 +00:00
|
|
|
i := 0
|
2021-01-31 18:50:04 +00:00
|
|
|
for key, lang := range *ls {
|
|
|
|
opts[i] = [2]string{key, lang.Meta.Name}
|
2021-01-21 14:16:03 +00:00
|
|
|
i++
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
2021-01-31 18:50:04 +00:00
|
|
|
return opts
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 21:26:54 +00:00
|
|
|
type commonLangs map[string]commonLang
|
|
|
|
|
|
|
|
type commonLang struct {
|
2023-06-18 11:27:18 +00:00
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
Notifications langSection `json:"notifications"`
|
|
|
|
QuantityStrings map[string]quantityString `json:"quantityStrings"`
|
2021-01-25 21:26:54 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-06-16 13:43:37 +00:00
|
|
|
type userLangs map[string]userLang
|
2021-01-19 00:29:29 +00:00
|
|
|
|
2023-06-16 13:43:37 +00:00
|
|
|
func (ls *userLangs) getOptions() [][2]string {
|
2021-01-31 18:50:04 +00:00
|
|
|
opts := make([][2]string, len(*ls))
|
2021-01-19 00:29:29 +00:00
|
|
|
i := 0
|
2021-01-31 18:50:04 +00:00
|
|
|
for key, lang := range *ls {
|
|
|
|
opts[i] = [2]string{key, lang.Meta.Name}
|
2021-01-21 14:16:03 +00:00
|
|
|
i++
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
2021-01-31 18:50:04 +00:00
|
|
|
return opts
|
2021-01-18 22:06:50 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 13:43:37 +00:00
|
|
|
type userLang 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
|
2023-06-18 11:27:18 +00:00
|
|
|
QuantityStrings map[string]quantityString `json:"quantityStrings"`
|
2023-06-16 17:29:49 +00:00
|
|
|
JSON string
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 21:41:28 +00:00
|
|
|
type pwrLangs map[string]pwrLang
|
|
|
|
|
|
|
|
func (ls *pwrLangs) getOptions() [][2]string {
|
|
|
|
opts := make([][2]string, len(*ls))
|
|
|
|
i := 0
|
|
|
|
for key, lang := range *ls {
|
|
|
|
opts[i] = [2]string{key, lang.Meta.Name}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
|
|
|
|
type pwrLang struct {
|
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
}
|
|
|
|
|
2021-01-19 00:29:29 +00:00
|
|
|
type emailLangs map[string]emailLang
|
|
|
|
|
2021-01-31 18:50:04 +00:00
|
|
|
func (ls *emailLangs) getOptions() [][2]string {
|
|
|
|
opts := make([][2]string, len(*ls))
|
2021-01-19 00:29:29 +00:00
|
|
|
i := 0
|
2021-01-31 18:50:04 +00:00
|
|
|
for key, lang := range *ls {
|
|
|
|
opts[i] = [2]string{key, lang.Meta.Name}
|
2021-01-21 14:16:03 +00:00
|
|
|
i++
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
2021-01-31 18:50:04 +00:00
|
|
|
return opts
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type emailLang struct {
|
2024-07-28 15:02:47 +00:00
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
UserCreated langSection `json:"userCreated"`
|
|
|
|
InviteExpiry langSection `json:"inviteExpiry"`
|
|
|
|
PasswordReset langSection `json:"passwordReset"`
|
|
|
|
UserDeleted langSection `json:"userDeleted"`
|
|
|
|
UserDisabled langSection `json:"userDisabled"`
|
|
|
|
UserEnabled langSection `json:"userEnabled"`
|
|
|
|
UserExpiryAdjusted langSection `json:"userExpiryAdjusted"`
|
|
|
|
InviteEmail langSection `json:"inviteEmail"`
|
|
|
|
WelcomeEmail langSection `json:"welcomeEmail"`
|
|
|
|
EmailConfirmation langSection `json:"emailConfirmation"`
|
|
|
|
UserExpired langSection `json:"userExpired"`
|
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-03-20 18:00:01 +00:00
|
|
|
Updates langSection `json:"updates"`
|
2023-10-19 16:19:52 +00:00
|
|
|
Proxy langSection `json:"proxy"`
|
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"`
|
2024-08-04 18:03:00 +00:00
|
|
|
Jellyseerr langSection `json:"jellyseerr"`
|
2021-01-25 21:26:54 +00:00
|
|
|
Email langSection `json:"email"`
|
2021-06-23 14:44:48 +00:00
|
|
|
Messages langSection `json:"messages"`
|
2021-01-25 21:26:54 +00:00
|
|
|
Notifications langSection `json:"notifications"`
|
2023-06-26 20:29:49 +00:00
|
|
|
UserPage langSection `json:"userPage"`
|
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
|
|
|
}
|
|
|
|
|
2021-01-31 18:50:04 +00:00
|
|
|
func (ls *setupLangs) getOptions() [][2]string {
|
|
|
|
opts := make([][2]string, len(*ls))
|
2021-01-25 21:26:54 +00:00
|
|
|
i := 0
|
2021-01-31 18:50:04 +00:00
|
|
|
for key, lang := range *ls {
|
|
|
|
opts[i] = [2]string{key, lang.Meta.Name}
|
2021-01-25 21:26:54 +00:00
|
|
|
i++
|
|
|
|
}
|
2021-01-31 18:50:04 +00:00
|
|
|
return opts
|
2021-01-25 21:26:54 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 00:08:12 +00:00
|
|
|
type telegramLangs map[string]telegramLang
|
|
|
|
|
|
|
|
type telegramLang struct {
|
|
|
|
Meta langMeta `json:"meta"`
|
|
|
|
Strings langSection `json:"strings"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ts *telegramLangs) getOptions() [][2]string {
|
|
|
|
opts := make([][2]string, len(*ts))
|
|
|
|
i := 0
|
|
|
|
for key, lang := range *ts {
|
|
|
|
opts[i] = [2]string{key, lang.Meta.Name}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
|
2021-01-19 00:29:29 +00:00
|
|
|
type langSection map[string]string
|
2021-02-19 17:50:50 +00:00
|
|
|
type tmpl map[string]string
|
|
|
|
|
2021-02-20 00:22:40 +00:00
|
|
|
func templateString(text string, vals tmpl) string {
|
2021-03-27 16:07:22 +00:00
|
|
|
start, previousEnd := -1, -1
|
|
|
|
out := ""
|
|
|
|
for i := range text {
|
|
|
|
if text[i] == '{' {
|
|
|
|
start = i
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if start != -1 && text[i] == '}' {
|
|
|
|
varName := text[start+1 : i]
|
|
|
|
val, ok := vals[varName]
|
|
|
|
if !ok {
|
|
|
|
start = -1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
out += text[previousEnd+1:start] + val
|
|
|
|
previousEnd = i
|
|
|
|
start = -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if previousEnd != len(text)-1 {
|
|
|
|
out += text[previousEnd+1:]
|
2021-02-19 17:50:50 +00:00
|
|
|
}
|
2021-03-27 16:07:22 +00:00
|
|
|
return out
|
2021-02-19 17:50:50 +00:00
|
|
|
}
|
2021-01-19 00:29:29 +00:00
|
|
|
|
2021-02-20 00:22:40 +00:00
|
|
|
func (el langSection) template(field string, vals tmpl) string {
|
|
|
|
text := el.get(field)
|
|
|
|
return templateString(text, vals)
|
|
|
|
}
|
|
|
|
|
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)
|
2021-03-27 16:07:22 +00:00
|
|
|
start, previous := -1, -3
|
|
|
|
out := ""
|
|
|
|
val := 0
|
|
|
|
for i := range text {
|
|
|
|
if i == len(text)-2 { // Check if there's even enough space for a {n}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if text[i:i+3] == "{n}" {
|
|
|
|
start = i
|
|
|
|
out += text[previous+3:start] + vals[val]
|
|
|
|
previous = start
|
|
|
|
val++
|
|
|
|
if val == len(vals) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if previous+2 != len(text)-1 {
|
|
|
|
out += text[previous+3:]
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
2021-03-27 16:07:22 +00:00
|
|
|
return out
|
2021-01-19 00:29:29 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|