由于 i18n 无法在 Github 页面上查阅, 我以 < a href=" https://stackoverflow.com/a/29757806/48136" 为基础, 回答@Kleo Petroff 和 < a href=" https://stackoverflow.com/a/329914455/48136" 回答@Falc 的 。
代码几乎完全一样,
{% capture i18n_date %}
{{ page.date | date: "%-d" }}
{% assign m = page.date | date: "%-m" | minus: 1 %}
{{ site.data.fr.months[m] }}
{{ page.date | date: "%Y" }}
{% endcapture %}
我在上述代码中设定了以下数据结构(可以是 ,也可以是 文件),文件是 :
months:
- Janvier
- Février
- Mars
- Avril
- Mai
- Juin
- Juillet
- Aout
- Septembre
- Octobre
- Novembre
- Décembre
Note that page.date | date: "%-m"
output the month number as a string, ie June number is actually "6"
not 6
, liquid silently casts that string to a number when piping the minus
filter.
During development it was not something I was aware and thus liquid didn t returned anything when passing m
with the value "6" to site.data.fr.months[m]
, I only saw the trick when looking at Falc answer.