Archives - Translating the date

Hello,

I would like to display the dates in different languages.
Also, the standard list display “1 May 2019” instead of “May 2019”.

How in that file can I add the automatic translation (to french for example) and at the same time remove the number of the day ?

Sorry I do not have enough knowledge to understand the cookbook yet.
I would like to use the second approach.

Thank you for reading.

Have you found a solution?

@01K, Have you tried his suggestion?

Yes, I’ve used this construction: {{ 'GRAV.MONTHS_OF_THE_YEAR'|ta(post.date|date('n') - 1) }} {{ post.date|date('d') }}
Somewhere on GitHub I’ve found a comment, that GRAV.MONTHS_OF_THE_YEAR already doesn’t take data from ‘languages.yaml’.

But the problem is that it only shows the current month date

@01K,

Try the following:

  • Fresh install of Grav 1.7.3
  • Add the following to frontmatter of ‘01.home/default.md’
    title: Home
    date: 03/03/2021
    
  • Add the following to ‘/user/themes/quark/templates/default.html.twig’:
    {{ 'GRAV.MONTHS_OF_THE_YEAR'|ta(page.date|date('n') - 1) }} {{ page.date|date('d') }}
    
  • Browse to ‘localhost/home’. Page will show ‘March 03’ using the correct current language for the month.

Somewhere on GitHub I’ve found a comment, that GRAV.MONTHS_OF_THE_YEAR already doesn’t take data from ‘languages.yaml’.

  • Where?
  • The literal GRAV.MONTHS_OF_THE_YEAR will get its value from ‘/system/languages/<your language>.yaml’. And can be overridden by creating file '/user/languages/<your language>.yaml
1 Like

Yes, your example works.
But problem is that I need to take a date from archives plugin, the default output looks like: {{ month|date(config.plugins.archives.date_display_format) }}

So, the {{ 'GRAV.MONTHS_OF_THE_YEAR'|ta(page.date|date('n') - 1) }} {{ page.date|date('d') }}
should be changed in something like:
{{ 'GRAV.MONTHS_OF_THE_YEAR'|ta(blog.date|date('n') - 1) }} {{ blog.date|date('d') }} as I think, but it doesn’t work.

Where?
Here is a link

@01K ,
I presume you would like to translate ‘January 2021’ into ‘YourJanuary 2021’. Right?

  • Create file ‘/user/translations/<your language>.yaml’
  • Add:
    January: <January in your language>
    February: <February in your language>
    
  • Check if theme has file ‘/templates/partials/archives.html.twig’
    • if not: Copy file ‘/user/plugins/archives/templates/partials/archives.html.twig’ into ‘/user/themes/<yourtheme>/templates/partials’
  • Edit ‘/user/themes/<yourtheme>/templates/partials/archives.html.twig’.
    Replace:
    <span class="archive_date">{{ month|date(config.plugins.archives.date_display_format) }}
    
    with:
    {% set dateParts = month|split(' ') %}
    <span class="archive_date">{{ dateParts[0]|t }} {{ dateParts[1]}}</span>
    

Note:
This should be done in an inherited theme. If not, all changes to templates will be lost when a new version of the theme arrives.

1 Like

Thank you!
This does work!