From 297efaa4a65a710d3ef5ffbb86cc44bc15904a16 Mon Sep 17 00:00:00 2001 From: schreifuchs Date: Mon, 28 Sep 2026 09:52:22 +0200 Subject: [PATCH] fix(translations): stay on page --- internal/components/translate/context.go | 8 ++++ web/layouts/base.templ | 59 +++++++++++++++--------- web/layouts/render.go | 2 +- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/internal/components/translate/context.go b/internal/components/translate/context.go index d1f8e78..8a3ab5b 100644 --- a/internal/components/translate/context.go +++ b/internal/components/translate/context.go @@ -53,13 +53,21 @@ func Path(ctx context.Context, pp ...string) string { } func PathForLang(ctx context.Context, lang string, pp ...string) string { + slog.Debug("computing path for lang", "pp", pp, "lang", lang) s, ok := ctx.Value(serviceKey).(*Service) if !ok { slog.Error("could not extract translation service from context for translating path", "ctx", ctx, "path", pp) return path.Join(pp...) } + // remove leading "" + for len(pp) > 0 && pp[0] == "" { + pp = pp[1:] + } + if len(pp) > 0 { + + slog.Debug("computing path for lang", "pp", pp, "lang", lang, "pp[0]", pp[0], "translations", s.translations) if _, ok := s.translations[pp[0]]; ok { pp = pp[1:] } diff --git a/web/layouts/base.templ b/web/layouts/base.templ index e637e1e..13fb5a7 100644 --- a/web/layouts/base.templ +++ b/web/layouts/base.templ @@ -7,7 +7,7 @@ import ( "strings" ) -templ Head(cfg config.Cfg, title string) { +templ head(cfg config.Cfg, title string) { @@ -29,29 +29,42 @@ templ Head(cfg config.Cfg, title string) { templ Base(cfg config.Cfg, title string) { - @Head(cfg, title) - -
- schreifuchs.ch - -
-
+ @head(cfg, title) + + @body() { { children... } -
+ } } + +templ Content(cfg config.Cfg, title string) { + @head(cfg, title) + @body() { + { children... } + } +} + +templ body() { +
+ schreifuchs.ch + +
+
+ { children... } +
+} diff --git a/web/layouts/render.go b/web/layouts/render.go index eef60a2..dd78bc2 100644 --- a/web/layouts/render.go +++ b/web/layouts/render.go @@ -36,7 +36,7 @@ func (l *Layouts) Render(ctx context.Context, w io.Writer, r *http.Request, comp component = Base(l.cfg, title) } else { ctx = templ.WithChildren(ctx, component) - component = Head(l.cfg, title) + component = Content(l.cfg, title) } if err := component.Render(ctx, w); err != nil {