Merge pull request #126 from akuma06/master
Fixed Typo + Added multi language support
Cette révision appartient à :
révision
9506e29163
7 fichiers modifiés avec 33 ajouts et 6 suppressions
1
.gitignore
externe
1
.gitignore
externe
|
@ -9,5 +9,6 @@ nyaa-master.exe
|
|||
*.swp
|
||||
.vscode
|
||||
templates/*.html.go
|
||||
*.bat
|
||||
*.backup
|
||||
tags
|
||||
|
|
7
main.go
7
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/db"
|
||||
|
@ -15,6 +16,11 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func initI18N() {
|
||||
/* Initialize the languages translation */
|
||||
i18n.MustLoadTranslationFile("service/user/locale/en-us.all.json")
|
||||
}
|
||||
|
||||
func RunServer(conf *config.Config) {
|
||||
http.Handle("/", router.Router)
|
||||
|
||||
|
@ -47,6 +53,7 @@ func main() {
|
|||
log.CheckError(err)
|
||||
}
|
||||
db.ORM, _ = db.GormInit(conf)
|
||||
initI18N()
|
||||
RunServer(conf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
"math"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
|
||||
var FuncMap = template.FuncMap{
|
||||
"min": math.Min,
|
||||
|
@ -57,4 +58,5 @@ var FuncMap = template.FuncMap{
|
|||
}
|
||||
return template.HTML(ret)
|
||||
},
|
||||
"T": i18n.IdentityTfunc,
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
|
||||
"github.com/ewhal/nyaa/service/user/form"
|
||||
"github.com/ewhal/nyaa/util/modelHelper"
|
||||
"github.com/ewhal/nyaa/util/languages"
|
||||
"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"))
|
||||
|
||||
|
@ -21,9 +21,9 @@ func init() {
|
|||
// Getting View User Registration
|
||||
|
||||
func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
b := form.RegistrationForm{}
|
||||
modelHelper.BindValueForm(b, r)
|
||||
modelHelper.BindValueForm(&b, r)
|
||||
languages.SetTranslation("en-us", viewRegisterTemplate)
|
||||
htv := UserRegisterTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
err := viewTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
|
|
|
@ -18,5 +18,9 @@
|
|||
{
|
||||
"id": "reset_password_content",
|
||||
"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 "content"}}
|
||||
<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