Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fixed Typo + Added multi language support

Multi language for User package
Cette révision appartient à :
akuma06 2017-05-07 02:32:32 +02:00
Parent 550ce04143
révision e3be801f4d
7 fichiers modifiés avec 34 ajouts et 6 suppressions

1
.gitignore externe
Voir le fichier

@ -8,3 +8,4 @@ nyaa-master.exe
*.swp
.vscode
templates/*.html.go
*.bat

Voir le fichier

@ -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)
@ -45,6 +51,7 @@ func main() {
log.CheckError(err)
}
db.ORM, _ = db.GormInit(conf)
initI18N()
RunServer(conf)
}
}

Voir le fichier

@ -6,7 +6,8 @@ import (
"math"
"net/url"
"strconv"
"github.com/nicksnyder/go-i18n/i18n"
"github.com/ewhal/nyaa/templates"
)
@ -68,4 +69,5 @@ var FuncMap = template.FuncMap{
"SearchAdvanced": func(nav templates.Navigation, s templates.SearchForm) template.HTML {
return template.HTML(templates.SearchAdvanced(nav, s))
},
"T": i18n.IdentityTfunc,
}

Voir le fichier

@ -7,21 +7,22 @@ import(
"github.com/ewhal/nyaa/templates"
"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"))
// 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, 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 {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

Voir le fichier

@ -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"
}
]

Voir le fichier

@ -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
Voir le fichier

@ -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,
})
}