aboutsummaryrefslogtreecommitdiffhomepage
path: root/http
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-04-27 22:07:46 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-04-27 22:07:46 -0700
commitddd3af4b85f5a2fe85c17a9cc30cf54743b9eb59 (patch)
tree539b491fc9f67980b09a6ccd282454614a77f8b4 /http
parent6b360d08c1f6c8a6cd1b7608f7af734a3ceef8d7 (diff)
Do not use shared variable to translate templates
Diffstat (limited to 'http')
-rw-r--r--http/handler/context.go6
-rw-r--r--http/handler/handler.go7
-rw-r--r--http/handler/html_response.go4
3 files changed, 7 insertions, 10 deletions
diff --git a/http/handler/context.go b/http/handler/context.go
index 119a4d5..2d70271 100644
--- a/http/handler/context.go
+++ b/http/handler/context.go
@@ -85,7 +85,11 @@ func (c *Context) UserLanguage() string {
return user.Language
}
- return c.getContextStringValue(middleware.UserLanguageContextKey)
+ language := c.getContextStringValue(middleware.UserLanguageContextKey)
+ if language == "" {
+ language = "en_US"
+ }
+ return language
}
// Translate translates a message in the current language.
diff --git a/http/handler/handler.go b/http/handler/handler.go
index b88a885..59e8acd 100644
--- a/http/handler/handler.go
+++ b/http/handler/handler.go
@@ -41,13 +41,6 @@ func (h *Handler) Use(f ControllerFunc) http.Handler {
ctx := NewContext(r, h.store, h.router, h.translator)
request := NewRequest(r)
response := NewResponse(h.cfg, w, r, h.template)
- language := ctx.UserLanguage()
-
- if language != "" {
- h.template.SetLanguage(language)
- } else {
- h.template.SetLanguage("en_US")
- }
f(ctx, request, response)
})
diff --git a/http/handler/html_response.go b/http/handler/html_response.go
index 26e5270..4d0dbe5 100644
--- a/http/handler/html_response.go
+++ b/http/handler/html_response.go
@@ -19,9 +19,9 @@ type HTMLResponse struct {
}
// Render execute a template and send to the client the generated HTML.
-func (h *HTMLResponse) Render(template string, args map[string]interface{}) {
+func (h *HTMLResponse) Render(template, language string, args map[string]interface{}) {
h.writer.Header().Set("Content-Type", "text/html; charset=utf-8")
- h.template.Execute(h.writer, template, args)
+ h.template.Render(h.writer, template, language, args)
}
// ServerError sends a 500 error to the browser.