'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" ?
Solution 1:[1]
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.
Solution 2:[2]
How about:
{{ time.Format "02 January" .Key }}
Or is there something I am missing?
Update: You can sort by months like this:
{{ range (where site.RegularPages "Type" "in" site.Params.mainSections).GroupByDate "1 2006" -}}
Then you can split your .Key by a space and create a manual lookup for your localized month. Not very pretty, but it gets the job done.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | BoumTAC |
Solution 2 |