mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
Do not use shared variable to translate templates
This commit is contained in:
parent
6b360d08c1
commit
ddd3af4b85
21 changed files with 104 additions and 101 deletions
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue