Add custom function to get the current locale from templates

This is just to set the correct `lang` attribute on the HTML, so that
text readers can do its job and the `(optional)` suffix of labels gets
the correct ”translation”.
This commit is contained in:
jordi fita mas 2023-01-31 15:45:51 +01:00
parent 3b3c3bd302
commit e0abf98bb1
3 changed files with 5 additions and 2 deletions

View File

@ -17,6 +17,9 @@ func mustRenderTemplate(wr io.Writer, r *http.Request, layout string, filename s
t.Funcs(template.FuncMap{
"gettext": locale.Get,
"pgettext": locale.GetC,
"currentLocale": func() string {
return locale.Language.String()
},
"companyURI": func(uri string) string {
if company == nil {
return uri

View File

@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="{{ currentLocale }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

View File

@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="{{ currentLocale }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">