From ee185e5f43596596c7dff6333756db99dc9a812a Mon Sep 17 00:00:00 2001 From: cblgh Date: Thu, 15 Apr 2021 20:14:04 +0200 Subject: [PATCH] don't render language picker if we have less than 2 translations --- web/handlers/http.go | 9 +++++++-- web/templates/base.tmpl | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/web/handlers/http.go b/web/handlers/http.go index 5545c00..0a1a920 100644 --- a/web/handlers/http.go +++ b/web/handlers/http.go @@ -123,10 +123,15 @@ func New( } }), - render.InjectTemplateFunc("listLanguages", func(r *http.Request) interface{} { + render.InjectTemplateFunc("language_count", func(r *http.Request) interface{} { + return func() int { + return len(locHelper.ListLanguages()) + } + }), + + render.InjectTemplateFunc("list_languages", func(r *http.Request) interface{} { urlTo := web.NewURLTo(m) route := urlTo(router.CompleteSetLanguage).String() - // seem to get an error when changing languages on pages that already embed a csrf token csrfElement := csrf.TemplateField(r) createFormElement := func(tag, translation string) string { diff --git a/web/templates/base.tmpl b/web/templates/base.tmpl index 5d77a93..40e0576 100644 --- a/web/templates/base.tmpl +++ b/web/templates/base.tmpl @@ -90,15 +90,18 @@ {{end}}
-
- - Language - -
- {{ listLanguages }} -
-
+ {{ $languages := language_count }} + {{ if gt $languages 1 }} +
+ + Language + +
+ {{ list_languages }} +
+
+ {{ end }}
{{end}}