Hi can anybody suggest me a quick way to display the blog dates in a language other than english? I am using the antimatter blog skeleton. Thanks in advance.
Luca
The dates are formatted using the standard PHP date formatting syntax.
http://php.net/manual/en/function.date.php
You would just need to edit that syntax in the Twig template that renders the particular page. Probably templates/partials/blog_item.html.twig
Try this code (month names in Polish):
—php
{% set miesiace = [‘Styczeń’, ‘Luty’ , ’ Marzec’ , ‘Kwiecień’, ‘Maj’, ‘Czerwiec’, ‘Lipiec’, ‘Sierpeiń’, ‘Wrzesień’, ‘Październik’, ‘Listopad’, ‘Grudzień’] %}
{% set nrMiesiaca = page.date|date(“n”) %}
{% set miesiac = miesiace[nrMiesiaca-1] %}
<span>{{ page.date|date("d") }}</span>
<em>{{ miesiac }}</em>
</span>
thanks to both, I’ll try the solution Kuba Jarosz proposed, with names in italian (:D). I think we are missing a serious effort on internalization of grav
the thing worked perfectly, I’m posting it here for the Italians interested:
<span class="list-blog-date">
{% set mesi = ['Gennaio', 'Febbraio' , 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'] %}
{% set nrMese = page.date|date("n") %}
{% set mese = mesi[nrMese -1] %}
<span>{{ page.date|date("d") }}</span>
<em>{{ mese }}</em>
</span>
Now I’ll try to do something similar for the Archive snippet, any help is welcome
@lucam you must edit archives.html.twig
template in user/plugins/archives/template/partials
folder. My code (not ideal, but working):
—php
-
{% if archives_show_count %}
{{ items|length }}
{% endif %}{% set nrMiesiaca = month|date("n") %} {% set miesiac = miesiace[nrMiesiaca-1] %} {% set rok = month|date("Y") %} <span class="archive_date">{{ miesiac }} {{ rok }}</span> </a> </li>
{% endfor %}
{% set miesiace = [‘Styczeń’, ‘Luty’ , ’ Marzec’ , ‘Kwiecień’, ‘Maj’, ‘Czerwiec’, ‘Lipiec’, ‘Sierpeiń’, ‘Wrzesień’, ‘Październik’, ‘Listopad’, ‘Grudzień’] %}
{% for month,items in archives_data %}
worked perfectly! I attach the translated version for the Italian readers. Thanks again!
-```
-
{% if archives_show_count %} <span class="label">{{ items|length }}</span> {% endif %} {% set nrMese = month|date("n") %} {% set mese = mesi[nrMese -1] %} {% set anno = month|date("Y") %} <span class="archive_date">{{ mese }} {{ anno }}</span> </a> </li>
{% endfor %}
{% set mesi = [‘Gennaio’, ‘Febbraio’ , ‘Marzo’, ‘Aprile’, ‘Maggio’, ‘Giugno’, ‘Luglio’, ‘Agosto’, ‘Settembre’, ‘Ottobre’, ‘Novembre’, ‘Dicembre’] %}
{% for month,items in archives_data %}
Muchas gracias. Lo he puesto en español en templates/partials/blog_item.html.twig
en mi blog.
— html
{% set meses = [‘Enero’, ‘Febrero’ , ‘Marzo’, ‘Abril’, ‘Mayo’, ‘Junio’, ‘Julio’, ‘Agosto’, ‘Septiembre’, ‘Octubre’, ‘Noviembre’, ‘Diciembre’] %}
{% set nrMeses = page.date|date(“n”) %}
{% set mes = meses[nrMeses -1] %}
{{ page.date|date(“d”) }}
{{ mes }}
{{ page.date|date(“Y”) }}
También lo he aplicado al plugín de búsqueda, en la plantilla de resultados simplesearch_item.html.twig
en themes/antimatter/templates/partials.
Como se puede ver en esta página.