summaryrefslogtreecommitdiffhomepage
path: root/middleware
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-08-07 01:45:48 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-08-07 01:45:48 +0200
commite555accb612e189ab9bdad403958d4e0a6d809ae (patch)
tree319c4937a165a4b867a42f1852c3362ba577c68d /middleware
parent7fbaed9158ac5c405ee3150c2bf27af8ec1380ba (diff)
Redirect the user after a language is set
Diffstat (limited to 'middleware')
-rw-r--r--middleware/i18n.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/middleware/i18n.go b/middleware/i18n.go
index 5e33636..a30a9f6 100644
--- a/middleware/i18n.go
+++ b/middleware/i18n.go
@@ -28,12 +28,15 @@ func I18n(next http.Handler) http.Handler {
}
}
- used := cmp.Or(p, i18n.DefaultPrinter)
- ctx := context.WithValue(r.Context(), PrinterKey, used)
+ ctx := context.WithValue(
+ r.Context(), PrinterKey, cmp.Or(p, i18n.DefaultPrinter))
if p == pZero {
+ http.SetCookie(w, &http.Cookie{
+ Name: "redirect",
+ Value: r.URL.Path,
+ })
templates.Root(nil, templates.SetLanguage()).Render(ctx, w)
- /* TODO: Redirect the user back to where they came from */
} else {
next.ServeHTTP(w, r.WithContext(ctx))
}