Hugo, how to localized .groupByDate


In my template I sort by months my post like this:

{{ range (where site.RegularPages "Type" "in" site.Params.mainSections).GroupByDate "January, 2006" -}}
  <h1>{{ .Key }}</h1> // output: March, 2022
  {{ range (where .Pages ".Params.unlisted" "!=" "true") }}
    <div>{{ time.Format "02 January" .Date }} - {{ .Title }}</div> // output: 01 Mars - This is the title of my post
  {{ end }}
{{ end }}

For every post the time.Format localized my date in my language (here in French).

But the title witch is group by month is still in English (here it’s the h1). How can I format my {{ .Key }} so it can be localized in my own language and show "Mars, 2022" instead of "March, 2022" ?


Since hugo version 0.97 it works as expected, we don’t need some ugly hack to have the text in the corresponding language.

Now you can use .GroupByDate and it will use your language settings in your config file.

Answered By – BoumTAC

Answer Checked By – Dawn Plyler (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.