Fixed Typo + Added multi language support
Multi language for User package
Cette révision appartient à :
Parent
cae4cc6349
révision
f88b4656a1
7 fichiers modifiés avec 34 ajouts et 6 suppressions
1
.gitignore
externe
1
.gitignore
externe
|
@ -8,3 +8,4 @@ nyaa-master.exe
|
||||||
*.swp
|
*.swp
|
||||||
.vscode
|
.vscode
|
||||||
templates/*.html.go
|
templates/*.html.go
|
||||||
|
*.bat
|
7
main.go
7
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/nicksnyder/go-i18n/i18n"
|
||||||
|
|
||||||
"github.com/ewhal/nyaa/config"
|
"github.com/ewhal/nyaa/config"
|
||||||
"github.com/ewhal/nyaa/db"
|
"github.com/ewhal/nyaa/db"
|
||||||
|
@ -15,6 +16,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func initI18N() {
|
||||||
|
/* Initialize the languages translation */
|
||||||
|
i18n.MustLoadTranslationFile("service/user/locale/en-us.all.json")
|
||||||
|
}
|
||||||
|
|
||||||
func RunServer(conf *config.Config) {
|
func RunServer(conf *config.Config) {
|
||||||
http.Handle("/", router.Router)
|
http.Handle("/", router.Router)
|
||||||
|
|
||||||
|
@ -45,6 +51,7 @@ func main() {
|
||||||
log.CheckError(err)
|
log.CheckError(err)
|
||||||
}
|
}
|
||||||
db.ORM, _ = db.GormInit(conf)
|
db.ORM, _ = db.GormInit(conf)
|
||||||
|
initI18N()
|
||||||
RunServer(conf)
|
RunServer(conf)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"github.com/nicksnyder/go-i18n/i18n"
|
||||||
|
|
||||||
"github.com/ewhal/nyaa/templates"
|
"github.com/ewhal/nyaa/templates"
|
||||||
)
|
)
|
||||||
|
@ -68,4 +69,5 @@ var FuncMap = template.FuncMap{
|
||||||
"SearchAdvanced": func(nav templates.Navigation, s templates.SearchForm) template.HTML {
|
"SearchAdvanced": func(nav templates.Navigation, s templates.SearchForm) template.HTML {
|
||||||
return template.HTML(templates.SearchAdvanced(nav, s))
|
return template.HTML(templates.SearchAdvanced(nav, s))
|
||||||
},
|
},
|
||||||
|
"T": i18n.IdentityTfunc,
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,21 +7,22 @@ import(
|
||||||
"github.com/ewhal/nyaa/templates"
|
"github.com/ewhal/nyaa/templates"
|
||||||
"github.com/ewhal/nyaa/service/user/form"
|
"github.com/ewhal/nyaa/service/user/form"
|
||||||
"github.com/ewhal/nyaa/util/modelHelper"
|
"github.com/ewhal/nyaa/util/modelHelper"
|
||||||
|
"github.com/ewhal/nyaa/util/languages"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
var viewRegisterTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/user/register.html"))
|
var viewRegisterTemplate = template.Must(template.New("userRegister").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/user/register.html"))
|
||||||
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
|
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
|
||||||
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
|
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
|
||||||
|
|
||||||
// Getting View User Registration
|
// Getting View User Registration
|
||||||
|
|
||||||
func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
b := form.RegistrationForm{}
|
b := form.RegistrationForm{}
|
||||||
modelHelper.BindValueForm(b, r)
|
modelHelper.BindValueForm(&b, r)
|
||||||
|
languages.SetTranslation("en-us", viewRegisterTemplate)
|
||||||
htv := UserRegisterTemplateVariables{b, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
|
htv := UserRegisterTemplateVariables{b, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||||
err := viewTemplate.ExecuteTemplate(w, "index.html", htv)
|
err := viewRegisterTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,9 @@
|
||||||
{
|
{
|
||||||
"id": "reset_password_content",
|
"id": "reset_password_content",
|
||||||
"translation": "Please click below link to reset your password."
|
"translation": "Please click below link to reset your password."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":"register_title",
|
||||||
|
"translation": "Creating a new account"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{{define "title"}}{{.Torrent.Name}}{{end}}
|
{{define "title"}}{{ T "register_title" }}{{end}}
|
||||||
{{define "contclass"}}cont-view{{end}}
|
{{define "contclass"}}cont-view{{end}}
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<div class="blockBody">
|
<div class="blockBody">
|
||||||
|
|
13
util/languages/translation.go
Fichier normal
13
util/languages/translation.go
Fichier normal
|
@ -0,0 +1,13 @@
|
||||||
|
package languages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nicksnyder/go-i18n/i18n"
|
||||||
|
"html/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetTranslation(language string, template *template.Template) {
|
||||||
|
T, _ := i18n.Tfunc(language)
|
||||||
|
template.Funcs(map[string]interface{}{
|
||||||
|
"T": T,
|
||||||
|
})
|
||||||
|
}
|
Référencer dans un nouveau ticket