In my list template I use
{{ .Date.Format β2. January 2006β }}
to generate dates dates for my blog posts. This works fine. The problem is that my blog is in Slovak and this always generates English dates, which looks strange.
Is there any way to force a language/locale when generating the dates?
Would it be possible to set a variable called locale
in the frontmatter? Inside a template you could use a simple if-else statement for showing the right date format depending on the locale:
{{ if eq .Params.locale "sk" }}
<!-- YOUR LOCALIZED DATE FORMAT -->
{{ else }}
{{ .Date.Format "2. January 2006" }}
{{ end }}
Otherwise, if you only blog in Slovak, I suggest to simply change the dateformat in the template manually.
I guess I did not write the question right The format {{ .Date.Format β2. January 2006β }} is ok. The problem is, it generates 4. January 2016 in English instead of 4. januΓ‘r 2016 in Slovak.
My fault, I misinterpreted your question. I remember a user with the same question and found the thread again:
I hope the presented solution works for you since it is some sort of workaround. Currently, Goβs templates donβt support localization.
1 Like
Nice workaround, thanks! I got it working using the suggested solutions. It is a shame the Go templating language does not support it directly.