I am trying out jekyll for website creation. I am using jekyll-bootstrap.
The default configuration has the page archive, where all the posts are listed grouped by year and month of the post date. Currently the months appear in English. I've looked at the code and this is an excerpt which is responsible for putting the date:
{% capture this_month %}{{ post.date | date: "%B" }}{% endcapture %}
I've found a lot of information here, so there is a way to specify the desired locale. But how can you make jekyll respect it? Simply adding
default_locale: "lt"
in _config.yml
naturally does not work.
You can overwrite the current month by using Liquid Date Format:
{% assign m = page.date | date: "%-m" %} {{ page.date | date: "%-d" }} {% case m %} {% when '1' %}Januar {% when '2' %}Februar {% when '3' %}März {% when '4' %}April {% when '5' %}Mai {% when '6' %}Juni {% when '7' %}Juli {% when '8' %}August {% when '9' %}September {% when '10' %}Oktober {% when '11' %}November {% when '12' %}Dezember {% endcase %} {{ page.date | date: "%Y" }}
If your date is, for example 2015-02-20, the output will be 20 Februar 2015
Because i18n is not available on github pages, I built upon answer of @Kleo Petroff and the answer of @Falc, I set up a way to have a date with locale names defined in a YAML file :
The code is almost the same without the whole case statement :
{% 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 %}
I set the following data-structure (could be in _config.yml
, or in some _data/some.yml
file), in the above code the file is _data/fr.yml
:
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
mwith the value "6" to
site.data.fr.months[m]`, I only saw the trick when looking at Falc answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With