英文:
Hugo, how to localized .groupByDate
问题
在我的模板中,我按月份对我的帖子进行排序,就像这样:
{{ range (where site.RegularPages "Type" "in" site.Params.mainSections).GroupByDate "January, 2006" -}}
<h1>{{ .Key }}</h1> // 输出:March, 2022
{{ range (where .Pages ".Params.unlisted" "!=" "true") }}
<div>{{ time.Format "02 January" .Date }} - {{ .Title }}</div> // 输出:01 Mars - This is the title of my post
{{ end }}
{{ end }}
对于每篇帖子,time.Format
会将我的日期本地化为我的语言(这里是法语)。
但是按月份分组的标题仍然是英文的(这里是h1
)。我该如何格式化我的{{ .Key }}
,以便它可以本地化为我的语言,并显示为“Mars, 2022”而不是“March, 2022”?
英文:
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" ?
答案1
得分: 1
如何这样处理:
{{ time.Format "02 January" .Key }}
或者我有什么遗漏的地方吗?
更新:你可以像这样按月份排序:
{{ range (where site.RegularPages "Type" "in" site.Params.mainSections).GroupByDate "1 2006" -}}
然后你可以通过空格拆分 .Key,并为本地化的月份创建一个手动查找。虽然不太美观,但可以完成工作。
英文:
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.
答案2
得分: 0
自从Hugo版本0.97以后,它按预期工作,我们不再需要一些丑陋的技巧来使文本显示为相应的语言。
现在你可以使用.GroupByDate
,它将使用你配置文件中的语言设置。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论