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:
parent
3b3c3bd302
commit
e0abf98bb1
|
@ -17,6 +17,9 @@ func mustRenderTemplate(wr io.Writer, r *http.Request, layout string, filename s
|
||||||
t.Funcs(template.FuncMap{
|
t.Funcs(template.FuncMap{
|
||||||
"gettext": locale.Get,
|
"gettext": locale.Get,
|
||||||
"pgettext": locale.GetC,
|
"pgettext": locale.GetC,
|
||||||
|
"currentLocale": func() string {
|
||||||
|
return locale.Language.String()
|
||||||
|
},
|
||||||
"companyURI": func(uri string) string {
|
"companyURI": func(uri string) string {
|
||||||
if company == nil {
|
if company == nil {
|
||||||
return uri
|
return uri
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="{{ currentLocale }}">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="{{ currentLocale }}">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
Loading…
Reference in New Issue