Add localization for en-US and de-DE

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2017-08-04 21:16:00 +02:00
parent 3d5e6712a7
commit c74fb23cda
No known key found for this signature in database
GPG Key ID: DC2729FDD34BE99E
8 changed files with 253 additions and 28 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
ots
frontend/locale/*.untranslated.json

View File

@ -1,7 +1,10 @@
generate:
generate: l10n
coffee -c frontend/application.coffee
go generate
l10n:
cd frontend/locale && goi18n *
publish:
curl -sSLo golang.sh https://raw.githubusercontent.com/Luzifer/github-publish/master/golang.sh
bash golang.sh

120
assets.go

File diff suppressed because one or more lines are too long

View File

@ -50,7 +50,7 @@
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" id="newSecret"><i class="fa fa-plus"></i> New Secret</a></li>
<li><a href="#" id="newSecret"><i class="fa fa-plus"></i> {{T "btn-new-secret"}}</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
@ -61,11 +61,11 @@
<div class="col-md-8 col-md-push-2">
<div class="alert alert-danger" role="alert" id="notfound">
<i class="fa fa-question-circle" aria-hidden="true"></i>
This is not the secret you are looking for&hellip;
{{T "alert-secret-not-found"}}
</div>
<div class="alert alert-danger" role="alert" id="somethingwrong">
<i class="fa fa-question-circle" aria-hidden="true"></i>
Something went wrong. I'm very sorry about this&hellip;
{{T "alert-something-went-wrong"}}
</div>
</div>
</div>
@ -75,39 +75,39 @@
<div class="panel panel-primary" id="panelNewSecret">
<div class="panel-heading">
<h3 class="panel-title">Create a new secret</h3>
<h3 class="panel-title">{{T "title-new-secret"}}</h3>
</div>
<div class="panel-body">
<form id="formCreateSecret">
<div class="form-group">
<label for="secret">Secret data:</label>
<label for="secret">{{T "label-secret-data"}}</label>
<textarea class="form-control" rows="5" id="secret"></textarea>
</div>
<input class="btn btn-success" type="submit" value="Create the secret!">
<input class="btn btn-success" type="submit" value="{{T "btn-create-secret"}}">
</form>
</div>
</div>
<div class="panel panel-success" id="panelSecretURL">
<div class="panel-heading">
<h3 class="panel-title">Secret created!</h3>
<h3 class="panel-title">{{T "title-secret-created"}}</h3>
</div>
<div class="panel-body">
<p>
Your secret was created and stored using this URL:
{{T "text-pre-url"}}
</p>
<div class="form-group">
<input type="text" class="form-control" readonly>
</div>
<p>
Please remember not to go to this URL yourself as that would destroy the secret. Just pass it to someone else!
{{T "text-burn-hint"}}
</p>
</div>
</div>
<div class="panel panel-primary" id="panelReadSecret">
<div class="panel-heading">
<h3 class="panel-title">Reading your secret...</h3>
<h3 class="panel-title">{{T "title-reading-secret"}}</h3>
</div>
<div class="panel-body">
<div class="form-group">
@ -115,7 +115,7 @@
</div>
<p>
<strong>Attention:</strong> You're only seeing this once. As soon as you reload the page the secret will be gone so maybe copy it now&hellip;
{{T "text-hint-burned"}}
</p>
</div>
</div>
@ -125,7 +125,7 @@
<div class="row">
<div class="col-md-12 footer">
Powered by <a href="https://github.com/Luzifer/ots"><i class="fa fa-github"></i> Luzifer/OTS</a>
{{T "text-powered-by"}} <a href="https://github.com/Luzifer/ots"><i class="fa fa-github"></i> Luzifer/OTS</a>
</div>
</div>
</div>

View File

@ -0,0 +1,38 @@
{
"alert-secret-not-found": {
"other": "Das ist nicht das Secret, was du suchst\u0026hellip;"
},
"alert-something-went-wrong": {
"other": "Irgendwas ging schief. Entschuldigung\u0026hellip;"
},
"btn-create-secret": {
"other": "Secret erstellen!"
},
"btn-new-secret": {
"other": "Neues Secret"
},
"label-secret-data": {
"other": "Inhalt des Secrets:"
},
"text-burn-hint": {
"other": "Bitte rufe die URL nicht selbst auf, da das Secret dadurch zerstört würde. Gib sie einfach weiter!"
},
"text-hint-burned": {
"other": "\u003cstrong\u003eAchtung:\u003c/strong\u003e Du kannst das nur einmal ansehen! Sobald du die Seite neu lädst, ist das Secret verschwunden, also besser direkt kopieren und sicher abspeichern\u0026hellip;"
},
"text-powered-by": {
"other": "Läuft mit"
},
"text-pre-url": {
"other": "Dein Secret wurde angelegt und unter folgender URL gespeichert:"
},
"title-new-secret": {
"other": "Erstelle ein neues Secret"
},
"title-reading-secret": {
"other": "Secret auslesen\u0026hellip;"
},
"title-secret-created": {
"other": "Secret erstellt!"
}
}

View File

@ -0,0 +1,38 @@
{
"alert-secret-not-found": {
"other": "This is not the secret you are looking for\u0026hellip;"
},
"alert-something-went-wrong": {
"other": "Something went wrong. I'm very sorry about this\u0026hellip;"
},
"btn-create-secret": {
"other": "Create the secret!"
},
"btn-new-secret": {
"other": "New Secret"
},
"label-secret-data": {
"other": "Secret data:"
},
"text-burn-hint": {
"other": "Please remember not to go to this URL yourself as that would destroy the secret. Just pass it to someone else!"
},
"text-hint-burned": {
"other": "\u003cstrong\u003eAttention:\u003c/strong\u003e You're only seeing this once. As soon as you reload the page the secret will be gone so maybe copy it now\u0026hellip;"
},
"text-powered-by": {
"other": "Powered by"
},
"text-pre-url": {
"other": "Your secret was created and stored using this URL:"
},
"title-new-secret": {
"other": "Create a new secret"
},
"title-reading-secret": {
"other": "Reading your secret\u0026hellip;"
},
"title-secret-created": {
"other": "Secret created!"
}
}

15
main.go
View File

@ -1,6 +1,6 @@
package main
//go:generate go-bindata -pkg $GOPACKAGE -o assets.go ./frontend
//go:generate go-bindata -pkg $GOPACKAGE -o assets.go ./frontend/...
import (
"fmt"
@ -9,6 +9,7 @@ import (
"os"
"path"
"strings"
"text/template"
http_helpers "github.com/Luzifer/go_helpers/http"
"github.com/Luzifer/rconfig"
@ -73,5 +74,15 @@ func assetDelivery(res http.ResponseWriter, r *http.Request) {
}
res.Header().Set("Content-Type", mime.TypeByExtension(ext))
res.Write(assetData)
tpl, err := template.New(assetName).Funcs(getTFuncMap(r)).Parse(string(assetData))
if err != nil {
log.Errorf("Template for asset %q has an error: %s", assetName, err)
return
}
tpl.Execute(res, map[string]interface{}{
"version": version,
})
}

40
translations.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"net/http"
"strings"
"text/template"
"github.com/nicksnyder/go-i18n/i18n"
log "github.com/sirupsen/logrus"
)
func init() {
for _, filename := range AssetNames() {
if !strings.HasPrefix(filename, "frontend/locale") || !strings.HasSuffix(filename, ".all.json") {
continue
}
translationData, _ := Asset(filename)
if err := i18n.ParseTranslationFileBytes(filename, translationData); err != nil {
log.Fatalf("Unable to load translation data %q: %s", filename, err)
}
}
}
func getTFuncMap(r *http.Request) template.FuncMap {
cookie, _ := r.Cookie("lang")
cookieLang := ""
if cookie != nil {
cookieLang = cookie.Value
}
qpLang := r.URL.Query().Get("hl")
acceptLang := r.Header.Get("Accept-Language")
defaultLang := "en-US" // known valid language
T, _ := i18n.Tfunc(cookieLang, qpLang, acceptLang, defaultLang)
return template.FuncMap{
"T": T,
}
}