don't render language picker if we have less than 2 translations

This commit is contained in:
cblgh 2021-04-15 20:14:04 +02:00
parent 93f84e04b0
commit ee185e5f43
2 changed files with 19 additions and 11 deletions

View File

@ -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 {

View File

@ -90,15 +90,18 @@
{{end}}
</div>
<div class="flex justify-center">
<details class="w-72">
<summary
class="mb-2 mx-auto px-3 py-1 text-gray-500 w-32 rounded shadow bg-gray-50 ring-1 ring-gray-300 hover:bg-gray-100 cursor-pointer">
Language
</summary>
<div class="grid grid-cols-2 justify-items-center gap-x-1">
{{ listLanguages }}
</div>
</details>
{{ $languages := language_count }}
{{ if gt $languages 1 }}
<details class="w-72">
<summary
class="mb-2 mx-auto px-3 py-1 text-gray-500 w-32 rounded shadow bg-gray-50 ring-1 ring-gray-300 hover:bg-gray-100 cursor-pointer">
Language
</summary>
<div class="grid grid-cols-2 justify-items-center gap-x-1">
{{ list_languages }}
</div>
</details>
{{ end }}
</div>
</footer>
{{end}}