From 05e32cd6787f3f5a48192a5604c5bd3e8e3defc7 Mon Sep 17 00:00:00 2001 From: Horus3 Date: Mon, 23 Mar 2015 23:17:51 +0100 Subject: German translation. --- handler.go | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'handler.go') diff --git a/handler.go b/handler.go index c99138e..f84dda0 100644 --- a/handler.go +++ b/handler.go @@ -16,18 +16,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { flash.Success = session.Flashes("success") session.Save(r, w) - /* - index := mainTempl.Lookup("index.html") - - err = index.ExecuteTemplate(w, "index.html", flash) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - */ - - err = ExecTemplate("index.html", w, flash) + err = ExecTemplate("index", w, r, flash) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -47,7 +36,7 @@ func RegisterHandler(w http.ResponseWriter, r *http.Request) { flash.Success = session.Flashes("success") session.Save(r, w) - err = ExecTemplate("register.html", w, flash) + err = ExecTemplate("register", w, r, flash) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -115,7 +104,7 @@ func AboutHandler(w http.ResponseWriter, r *http.Request) { flash.Success = session.Flashes("success") session.Save(r, w) - err = ExecTemplate("about.html", w, flash) + err = ExecTemplate("about", w, r, flash) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -135,7 +124,7 @@ func ServerHandler(w http.ResponseWriter, r *http.Request) { flash.Success = session.Flashes("success") session.Save(r, w) - err = ExecTemplate("server.html", w, flash) + err = ExecTemplate("server", w, r, flash) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -155,7 +144,7 @@ func HowtoHandler(w http.ResponseWriter, r *http.Request) { flash.Success = session.Flashes("success") session.Save(r, w) - err = ExecTemplate("howto.html", w, flash) + err = ExecTemplate("howto", w, r, flash) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -175,7 +164,7 @@ func UserHandler(w http.ResponseWriter, r *http.Request) { flash.Success = session.Flashes("success") session.Save(r, w) - err = ExecTemplate("user.html", w, flash) + err = ExecTemplate("user", w, r, flash) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -195,7 +184,7 @@ func PasswordHandler(w http.ResponseWriter, r *http.Request) { flash.Success = session.Flashes("success") session.Save(r, w) - err = ExecTemplate("password.html", w, flash) + err = ExecTemplate("password", w, r, flash) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -246,3 +235,22 @@ func ChangePasswordHandler(w http.ResponseWriter, r *http.Request) { session.Save(r, w) http.Redirect(w, r, "/user", 302) } + +func ChangeLocaleHandler(w http.ResponseWriter, r *http.Request) { + err := r.ParseForm() + if err != nil { + log.Panic(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + locale := r.URL.Query().Get("to") + + if len(locale) == 0 { + http.Redirect(w, r, "/", 302) + return + } + cookie := http.Cookie{Name: "lang", Value: locale} + http.SetCookie(w, &cookie) + http.Redirect(w, r, "/", 302) +} -- cgit v1.2.3