Generating localized dates in template

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" }}
{{ 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 :confused: 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.