1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

initial steps for localisation

This commit is contained in:
Harvey Tindall 2020-10-30 22:51:47 +00:00
parent 95c9f4f42d
commit d64d5c194f
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
8 changed files with 104 additions and 40 deletions

View File

@ -49,6 +49,17 @@
"name": "General",
"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": {
"name": "Default Look",
"required": false,

39
data/lang/form/en-us.json Normal file
View 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"
}
}
}
}

View File

@ -1,7 +1,8 @@
{{ define "form-base" }}
<script>
window.bs5 = {{ .bs5 }};
window.usernameEnabled = {{ .username }};
window.bs5 = {{ .settings.bs5 }};
window.usernameEnabled = {{ .settings.username }};
window.validationStrings = JSON.parse({{ .lang.validationStrings }});
</script>
<script src="form.js" type="module"></script>
{{ end }}

View File

@ -41,27 +41,27 @@
margin-bottom: 5%;
}
</style>
<title>Create Jellyfin Account</title>
<title>{{ .lang.pageTitle }}</title>
</head>
<body>
<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-content">
<div class="modal-header">
<h5 class="modal-title" id="successTitle">Success!</h5>
<h5 class="modal-title" id="successHeader">{{ .lang.successHeader }}</h5>
</div>
<div class="modal-body" id="successBody">
<p>{{ .successMessage }}</p>
</div>
<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 class="pageContainer">
<h1>
Create Account
{{ .lang.createAccountHeader }}
</h1>
<p>{{ .helpMessage }}</p>
<p class="contactBox">{{ .contactMessage }}</p>
@ -69,26 +69,26 @@
<div class="row" id="cardContainer">
<div class="col-sm">
<div class="card mb-3">
<div class="card-header">Details</div>
<div class="card-header">{{ .lang.accountDetails }}</div>
<div class="card-body">
<form action="#" method="POST" id="accountForm">
<div class="form-group">
<label for="inputEmail">Email</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>
<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="{{ .lang.emailAddress }}" value="{{ .email }}" required>
</div>
{{ if .settings.username }}
<div class="form-group">
<label for="inputUsername">Username</label>
<input type="username" class="form-control" id="inputUsername" name="username" placeholder="Username" required>
<label for="inputUsername">{{ .lang.username }}</label>
<input type="username" class="form-control" id="inputUsername" name="username" placeholder="{{ .lang.username }}" required>
</div>
{{ end }}
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password" required>
<label for="inputPassword">{{ .lang.password }}</label>
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="{{ .lang.password }}" required>
</div>
<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">
<span id="createAccount">Create Account</span>
<span id="createAccount">{{ .lang.createAccountButton }}</span>
</button>
</div>
</form>
@ -98,7 +98,7 @@
{{ if .validate }}
<div class="col-sm" id="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">
<ul class="list-group">
{{ range $key, $value := .requirements }}
@ -114,31 +114,10 @@
</div>
</div>
</div>
<script>
window.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>
window.validationStrings = {{ .lang.validationStrings }};
</script>
{{ template "form-base" .settings }}
{{ template "form-base" . }}
</body>
</html>

View File

@ -263,6 +263,12 @@ func start(asDaemon, firstCall bool) {
if app.loadConfig() != nil {
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()
// read from config...
debugMode = app.config.Section("ui").Key("debug").MustBool(false)

View File

@ -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) {
if ombi.key == "" {
return "", 401, fmt.Errorf("No API key provided")

View File

@ -14,6 +14,12 @@ type Storage struct {
profiles map[string]Profile
defaultProfile string
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
@ -49,6 +55,22 @@ func (st *Storage) storeInvites() error {
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 {
return loadJSON(st.emails_path, &st.emails)
}

View File

@ -1,6 +1,8 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
"strings"
@ -47,7 +49,11 @@ func (app *appContext) InviteProxy(gc *gin.Context) {
"bs5": app.config.Section("ui").Key("bs5").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 {
gc.HTML(404, "invalidCode.html", gin.H{
"bs5": app.config.Section("ui").Key("bs5").MustBool(false),