[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taldir] branch master updated: add i18n support
From: |
gnunet |
Subject: |
[taler-taldir] branch master updated: add i18n support |
Date: |
Sat, 11 Jan 2025 13:15:57 +0100 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository taldir.
The following commit(s) were added to refs/heads/master by this push:
new d96fc0f add i18n support
d96fc0f is described below
commit d96fc0f4795716c34d61148d9f67a318385e01f7
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Sat Jan 11 13:15:42 2025 +0100
add i18n support
---
go.mod | 9 +++++++--
locales/de-DE/taldir.yml | 6 ++++++
locales/en-US/taldir.yml | 6 ++++++
pkg/rest/taldir.go | 27 +++++++++++++++++++++++++--
web/templates/landing.html | 12 ++++++------
5 files changed, 50 insertions(+), 10 deletions(-)
diff --git a/go.mod b/go.mod
index f6aaad9..9ba0567 100644
--- a/go.mod
+++ b/go.mod
@@ -8,13 +8,15 @@ require (
github.com/schanzen/taler-go v1.0.6
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
gnunet v0.1.27
- gopkg.in/ini.v1 v1.66.6
+ gopkg.in/ini.v1 v1.67.0
gorm.io/driver/postgres v1.3.4
gorm.io/gorm v1.23.4
)
require (
+ github.com/BurntSushi/toml v1.2.1 // indirect
github.com/bfix/gospel v1.2.15 // indirect
+ github.com/gertd/go-pluralize v0.2.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.11.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
@@ -25,8 +27,11 @@ require (
github.com/jackc/pgx/v4 v4.15.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
+ github.com/kataras/i18n v0.0.8 // indirect
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 // indirect
- golang.org/x/text v0.3.7 // indirect
+ golang.org/x/net v0.9.0 // indirect
+ golang.org/x/text v0.9.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
)
replace gnunet v0.1.27 => ./third_party/gnunet-go/src/gnunet
diff --git a/locales/de-DE/taldir.yml b/locales/de-DE/taldir.yml
new file mode 100644
index 0000000..9d2a885
--- /dev/null
+++ b/locales/de-DE/taldir.yml
@@ -0,0 +1,6 @@
+phone: "Telefonnummer"
+email: "E-Mail"
+error: "Es ist ein Fehler aufgetreten!"
+title: "TalDir Alias Registration und Suche"
+selectAliasToLookupOrLink: "Bitte wähle einen Alias-Typ den Du suchen oder mit
einer Bezahlsystemaddresse verlinken möchtest."
+lookupOrRegister: "Suchen oder Verlinken"
diff --git a/locales/en-US/taldir.yml b/locales/en-US/taldir.yml
new file mode 100644
index 0000000..2f5cb81
--- /dev/null
+++ b/locales/en-US/taldir.yml
@@ -0,0 +1,6 @@
+phone: "Phone"
+email: "E-mail"
+error: "An error occured!"
+title: "TalDir Alias Registration and Lookup"
+selectAliasToLookupOrLink: "Select a type of alias that you want to look up or
link to a Payment System Address."
+lookupOrRegister: "Look up or register"
diff --git a/pkg/rest/taldir.go b/pkg/rest/taldir.go
index 3a8a4f3..895b693 100644
--- a/pkg/rest/taldir.go
+++ b/pkg/rest/taldir.go
@@ -43,6 +43,8 @@ import (
tos "github.com/schanzen/taler-go/pkg/rest"
talerutil "github.com/schanzen/taler-go/pkg/util"
"github.com/skip2/go-qrcode"
+ "github.com/kataras/i18n"
+ "github.com/gertd/go-pluralize"
"gopkg.in/ini.v1"
"gorm.io/driver/postgres"
"gorm.io/gorm"
@@ -107,6 +109,9 @@ type Taldir struct {
// Currency Spec
CurrencySpec talerutil.CurrencySpecification
+
+ // I18n
+ I18n *i18n.I18n
}
type Validator struct {
@@ -647,11 +652,12 @@ func (t *Taldir) privacyResponse(w http.ResponseWriter, r
*http.Request) {
func (t *Taldir) landingPage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
-
+ translateFunc := t.I18n.GetLocale(r).GetMessage
fullData := map[string]interface{}{
"validators": t.Validators,
"version": t.Version,
"error": r.URL.Query().Get("error"),
+ "tr": translateFunc,
}
err := t.LandingPageTpl.Execute(w, fullData)
if err != nil {
@@ -740,6 +746,16 @@ func (t *Taldir) setupHandlers() {
}
+var pluralizeClient = pluralize.NewClient()
+
+func getFuncs(current *i18n.Locale) template.FuncMap {
+ return template.FuncMap{
+ "plural": func(word string, count int) string {
+ return pluralizeClient.Pluralize(word, count, true)
+ },
+ }
+}
+
// Initialize the Taldir instance with cfgfile
func (t *Taldir) Initialize(cfgfile string, version string) {
_cfg, err := ini.LooseLoad(cfgfile)
@@ -748,6 +764,13 @@ func (t *Taldir) Initialize(cfgfile string, version
string) {
os.Exit(1)
}
t.Cfg = _cfg
+ t.I18n, err = i18n.New(i18n.Glob("./locales/*/*", i18n.LoaderConfig{
+ // Set custom functions per locale!
+ Funcs: getFuncs,
+ }), "en-US", "de-DE")
+ if err != nil {
+ panic(err)
+ }
if t.Cfg.Section("taldir").Key("production").MustBool(false) {
fmt.Println("Production mode enabled")
}
@@ -816,7 +839,7 @@ func (t *Taldir) Initialize(cfgfile string, version string)
{
if err := t.Db.AutoMigrate(&validation{}); err != nil {
panic(err)
}
- if
t.Cfg.Section("taldir").Key("purge_mappings_on_startup_dangerous").MustBool(false)
{
+ if
t.Cfg.Section("taldir").Key("purge_mappings_on_startup_dangerous").MustBool(false)
{
log.Println("DANGER Purging mappings!")
tx := t.Db.Where("1 = 1").Delete(&entry{})
log.Printf("Deleted %d entries.\n", tx.RowsAffected)
diff --git a/web/templates/landing.html b/web/templates/landing.html
index dc20351..04cdeeb 100644
--- a/web/templates/landing.html
+++ b/web/templates/landing.html
@@ -5,30 +5,30 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,
shrink-to-fit=no">
<link href="/css/bootstrap.min.css" rel="stylesheet">
- <title>TalDir Alias Registration and Lookup</title>
+ <title>{{ call .tr "title" }}</title>
</head>
<body>
<div class="container pt-5">
- <h1 class="text-center mb-5">TalDir Alias Registration and Lookup</h1>
+ <h1 class="text-center mb-5">{{ call .tr "title" }}</h1>
{{if .error}}
<div class="container pt-5">
<div id="ebanner" class="alert alert-danger" role="alert">
- <h4 class="alert-heading">An error occured!</h4>
+ <h4 class="alert-heading">{{ call .tr "error" }}</h4>
<hr>
<p class="mb-0">{{.error}}.</p>
</div>
</div>
{{end}}
<div id="ebanner" class="alert alert-info" role="alert">
- <h4 class="alert-heading">Look up or register</h4>
+ <h4 class="alert-heading">{{ call .tr "lookupOrRegister" }}</h4>
<hr>
- <p class="mb-0">Select a type of alias that you want to look up or
link to a Payment System Address.</p>
+ <p class="mb-0">{{ call .tr "selectAliasToLookupOrLink"}}</p>
</div>
<hr>
{{range .validators}}
<div class="row">
<div class="col-lg-4 mb-2 offset-lg-3 text-center d-grid gap-2">
- <a href="/landing/{{.Name}}" class="btn btn-primary
btn-block">{{.Name}}</a>
+ <a href="/landing/{{.Name}}" class="btn btn-primary btn-block">{{
call $.tr .Name}}</a>
</div>
</div>
{{end}}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taldir] branch master updated: add i18n support,
gnunet <=