mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-23 01:20:11 +00:00
initial steps for localisation
This commit is contained in:
parent
95c9f4f42d
commit
d64d5c194f
@ -49,6 +49,17 @@
|
|||||||
"name": "General",
|
"name": "General",
|
||||||
"description": "Settings related to the UI and program functionality."
|
"description": "Settings related to the UI and program functionality."
|
||||||
},
|
},
|
||||||
|
"language": {
|
||||||
|
"name": "Language",
|
||||||
|
"required": false,
|
||||||
|
"requires_restart": true,
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
"en-us"
|
||||||
|
],
|
||||||
|
"value": "en-US",
|
||||||
|
"description": "UI Language. Currently only implemented for account creation form. Submit a PR on github if you'd like to translate."
|
||||||
|
},
|
||||||
"theme": {
|
"theme": {
|
||||||
"name": "Default Look",
|
"name": "Default Look",
|
||||||
"required": false,
|
"required": false,
|
||||||
|
39
data/lang/form/en-us.json
Normal file
39
data/lang/form/en-us.json
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"meta": {
|
||||||
|
"name": "English (US)"
|
||||||
|
},
|
||||||
|
"strings": {
|
||||||
|
"pageTitle": "Create Jellyfin Account",
|
||||||
|
"createAccountHeader": "Create Account",
|
||||||
|
"accountDetails": "Details",
|
||||||
|
"emailAddress": "Email",
|
||||||
|
"username": "Username",
|
||||||
|
"password": "Password",
|
||||||
|
"createAccountButton": "Create Account",
|
||||||
|
"passwordRequirementsHeader": "Password Requirements",
|
||||||
|
"successHeader": "Success!",
|
||||||
|
"successContinueButton": "Continue",
|
||||||
|
"validationStrings": {
|
||||||
|
"length": {
|
||||||
|
"singular": "Must have at least {n} character",
|
||||||
|
"plural": "Must have a least {n} characters"
|
||||||
|
},
|
||||||
|
"uppercase": {
|
||||||
|
"singular": "Must have at least {n} uppercase character",
|
||||||
|
"plural": "Must have at least {n} uppercase characters"
|
||||||
|
},
|
||||||
|
"lowercase": {
|
||||||
|
"singular": "Must have at least {n} lowercase character",
|
||||||
|
"plural": "Must have at least {n} lowercase characters"
|
||||||
|
},
|
||||||
|
"number": {
|
||||||
|
"singular": "Must have at least {n} number",
|
||||||
|
"plural": "Must have at least {n} numbers"
|
||||||
|
},
|
||||||
|
"special": {
|
||||||
|
"singular": "Must have at least {n} special character",
|
||||||
|
"plural": "Must have at least {n} special characters"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
{{ define "form-base" }}
|
{{ define "form-base" }}
|
||||||
<script>
|
<script>
|
||||||
window.bs5 = {{ .bs5 }};
|
window.bs5 = {{ .settings.bs5 }};
|
||||||
window.usernameEnabled = {{ .username }};
|
window.usernameEnabled = {{ .settings.username }};
|
||||||
|
window.validationStrings = JSON.parse({{ .lang.validationStrings }});
|
||||||
</script>
|
</script>
|
||||||
<script src="form.js" type="module"></script>
|
<script src="form.js" type="module"></script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -41,27 +41,27 @@
|
|||||||
margin-bottom: 5%;
|
margin-bottom: 5%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<title>Create Jellyfin Account</title>
|
<title>{{ .lang.pageTitle }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="modal fade" id="successBox" tabindex="-1" role="dialog" aria-labelledby="successBox" aria-hidden="true" data-backdrop="static">
|
<div class="modal fade" id="successBox" tabindex="-1" role="dialog" aria-labelledby="successBox" aria-hidden="true" data-backdrop="static">
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title" id="successTitle">Success!</h5>
|
<h5 class="modal-title" id="successHeader">{{ .lang.successHeader }}</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body" id="successBody">
|
<div class="modal-body" id="successBody">
|
||||||
<p>{{ .successMessage }}</p>
|
<p>{{ .successMessage }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a href="{{ .jfLink }}" class="btn btn-primary">Continue</a>
|
<a href="{{ .jfLink }}" class="btn btn-primary">{{ .lang.successContinueButton }}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pageContainer">
|
<div class="pageContainer">
|
||||||
<h1>
|
<h1>
|
||||||
Create Account
|
{{ .lang.createAccountHeader }}
|
||||||
</h1>
|
</h1>
|
||||||
<p>{{ .helpMessage }}</p>
|
<p>{{ .helpMessage }}</p>
|
||||||
<p class="contactBox">{{ .contactMessage }}</p>
|
<p class="contactBox">{{ .contactMessage }}</p>
|
||||||
@ -69,26 +69,26 @@
|
|||||||
<div class="row" id="cardContainer">
|
<div class="row" id="cardContainer">
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<div class="card mb-3">
|
<div class="card mb-3">
|
||||||
<div class="card-header">Details</div>
|
<div class="card-header">{{ .lang.accountDetails }}</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form action="#" method="POST" id="accountForm">
|
<form action="#" method="POST" id="accountForm">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="inputEmail">Email</label>
|
<label for="inputEmail">{{ .lang.emailAddress }}</label>
|
||||||
<input type="email" class="form-control" id="{{ if .settings.username }}inputEmail{{ else }}inputUsername{{ end }}" name="{{ if .settings.username }}email{{ else }}username{{ end }}" placeholder="Email" value="{{ .email }}" required>
|
<input type="email" class="form-control" id="{{ if .settings.username }}inputEmail{{ else }}inputUsername{{ end }}" name="{{ if .settings.username }}email{{ else }}username{{ end }}" placeholder="{{ .lang.emailAddress }}" value="{{ .email }}" required>
|
||||||
</div>
|
</div>
|
||||||
{{ if .settings.username }}
|
{{ if .settings.username }}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="inputUsername">Username</label>
|
<label for="inputUsername">{{ .lang.username }}</label>
|
||||||
<input type="username" class="form-control" id="inputUsername" name="username" placeholder="Username" required>
|
<input type="username" class="form-control" id="inputUsername" name="username" placeholder="{{ .lang.username }}" required>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="inputPassword">Password</label>
|
<label for="inputPassword">{{ .lang.password }}</label>
|
||||||
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password" required>
|
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="{{ .lang.password }}" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group" role="group" aria-label="Button & Error" id="errorBox" style="margin-top: 1rem;">
|
<div class="btn-group" role="group" aria-label="Button & Error" id="errorBox" style="margin-top: 1rem;">
|
||||||
<button type="submit" class="btn btn-outline-primary" id="submitButton">
|
<button type="submit" class="btn btn-outline-primary" id="submitButton">
|
||||||
<span id="createAccount">Create Account</span>
|
<span id="createAccount">{{ .lang.createAccountButton }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -98,7 +98,7 @@
|
|||||||
{{ if .validate }}
|
{{ if .validate }}
|
||||||
<div class="col-sm" id="requirementBox">
|
<div class="col-sm" id="requirementBox">
|
||||||
<div class="card mb-3 requirementBox">
|
<div class="card mb-3 requirementBox">
|
||||||
<div class="card-header">Password Requirements</div>
|
<div class="card-header">{{ .lang.passwordRequirementsHeader }}</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{{ range $key, $value := .requirements }}
|
{{ range $key, $value := .requirements }}
|
||||||
@ -115,30 +115,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
window.validationStrings = {
|
window.validationStrings = {{ .lang.validationStrings }};
|
||||||
"length": {
|
|
||||||
"singular": "Must have at least {n} character",
|
|
||||||
"plural": "Must have a least {n} characters"
|
|
||||||
},
|
|
||||||
"uppercase": {
|
|
||||||
"singular": "Must have at least {n} uppercase character",
|
|
||||||
"plural": "Must have at least {n} uppercase characters"
|
|
||||||
},
|
|
||||||
"lowercase": {
|
|
||||||
"singular": "Must have at least {n} lowercase character",
|
|
||||||
"plural": "Must have at least {n} lowercase characters"
|
|
||||||
},
|
|
||||||
"number": {
|
|
||||||
"singular": "Must have at least {n} number",
|
|
||||||
"plural": "Must have at least {n} numbers"
|
|
||||||
},
|
|
||||||
"special": {
|
|
||||||
"singular": "Must have at least {n} special character",
|
|
||||||
"plural": "Must have at least {n} special characters"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
{{ template "form-base" .settings }}
|
{{ template "form-base" . }}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
6
main.go
6
main.go
@ -263,6 +263,12 @@ func start(asDaemon, firstCall bool) {
|
|||||||
if app.loadConfig() != nil {
|
if app.loadConfig() != nil {
|
||||||
app.err.Fatalf("Failed to load config file \"%s\"", app.config_path)
|
app.err.Fatalf("Failed to load config file \"%s\"", app.config_path)
|
||||||
}
|
}
|
||||||
|
lang := app.config.Section("ui").Key("language").MustString("en-us")
|
||||||
|
app.storage.lang.FormPath = filepath.Join(app.local_path, "lang", "form", lang+".json")
|
||||||
|
if _, err := os.Stat(app.storage.lang.FormPath); os.IsNotExist(err) {
|
||||||
|
app.storage.lang.FormPath = filepath.Join(app.local_path, "lang", "form", "en-us.json")
|
||||||
|
}
|
||||||
|
app.storage.loadLang()
|
||||||
app.version = app.config.Section("jellyfin").Key("version").String()
|
app.version = app.config.Section("jellyfin").Key("version").String()
|
||||||
// read from config...
|
// read from config...
|
||||||
debugMode = app.config.Section("ui").Key("debug").MustBool(false)
|
debugMode = app.config.Section("ui").Key("debug").MustBool(false)
|
||||||
|
2
ombi.go
2
ombi.go
@ -37,7 +37,7 @@ func newOmbi(server, key string, noFail bool) *Ombi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// does a GET and returns the response as an io.reader.
|
// does a GET and returns the response as a string.
|
||||||
func (ombi *Ombi) _getJSON(url string, params map[string]string) (string, int, error) {
|
func (ombi *Ombi) _getJSON(url string, params map[string]string) (string, int, error) {
|
||||||
if ombi.key == "" {
|
if ombi.key == "" {
|
||||||
return "", 401, fmt.Errorf("No API key provided")
|
return "", 401, fmt.Errorf("No API key provided")
|
||||||
|
22
storage.go
22
storage.go
@ -14,6 +14,12 @@ type Storage struct {
|
|||||||
profiles map[string]Profile
|
profiles map[string]Profile
|
||||||
defaultProfile string
|
defaultProfile string
|
||||||
emails, policy, configuration, displayprefs, ombi_template map[string]interface{}
|
emails, policy, configuration, displayprefs, ombi_template map[string]interface{}
|
||||||
|
lang Lang
|
||||||
|
}
|
||||||
|
|
||||||
|
type Lang struct {
|
||||||
|
FormPath string
|
||||||
|
Form map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// timePattern: %Y-%m-%dT%H:%M:%S.%f
|
// timePattern: %Y-%m-%dT%H:%M:%S.%f
|
||||||
@ -49,6 +55,22 @@ func (st *Storage) storeInvites() error {
|
|||||||
return storeJSON(st.invite_path, st.invites)
|
return storeJSON(st.invite_path, st.invites)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (st *Storage) loadLang() error {
|
||||||
|
err := loadJSON(st.lang.FormPath, &st.lang.Form)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
strings := st.lang.Form["strings"].(map[string]interface{})
|
||||||
|
validationStrings := strings["validationStrings"].(map[string]interface{})
|
||||||
|
vS, err := json.Marshal(validationStrings)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
strings["validationStrings"] = string(vS)
|
||||||
|
st.lang.Form["strings"] = strings
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (st *Storage) loadEmails() error {
|
func (st *Storage) loadEmails() error {
|
||||||
return loadJSON(st.emails_path, &st.emails)
|
return loadJSON(st.emails_path, &st.emails)
|
||||||
}
|
}
|
||||||
|
6
views.go
6
views.go
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -47,7 +49,11 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
|
|||||||
"bs5": app.config.Section("ui").Key("bs5").MustBool(false),
|
"bs5": app.config.Section("ui").Key("bs5").MustBool(false),
|
||||||
"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["strings"],
|
||||||
})
|
})
|
||||||
|
l, _ := json.MarshalIndent(app.storage.lang.Form, "", " ")
|
||||||
|
fmt.Println(app.storage.lang.Form["strings"].(map[string]interface{})["validationStrings"].(string))
|
||||||
|
fmt.Printf("%s\n", l)
|
||||||
} else {
|
} else {
|
||||||
gc.HTML(404, "invalidCode.html", gin.H{
|
gc.HTML(404, "invalidCode.html", gin.H{
|
||||||
"bs5": app.config.Section("ui").Key("bs5").MustBool(false),
|
"bs5": app.config.Section("ui").Key("bs5").MustBool(false),
|
||||||
|
Loading…
Reference in New Issue
Block a user