Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Archives - Translating the date

Solved by pamtbaau View solution

Started by M 7 years ago · 7 replies · 1163 views
7 years ago

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 ?

https://github.com/getgrav/grav-plugin-archives/blob/develop/templates/partials/archives.html.twig

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

Thank you for reading.

5 years ago

Have you found a solution?

5 years ago

@01K, Have you tried his suggestion?

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

5 years ago

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

5 years ago

@01K,

Try the following:

  • Fresh install of Grav 1.7.3
  • Add the following to frontmatter of '01.home/default.md'
    YAML
    title: Home
    date: 03/03/2021
    
  • Add the following to '/user/themes/quark/templates/default.html.twig':
    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
5 years ago

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

5 years ago Solution

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

  • Create file '/user/translations/<your language>.yaml'
  • Add:
    YAML
    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:
    TWIG
    <span class="archive_date">{{ month|date(config.plugins.archives.date_display_format) }}
    

    with:

    TWIG
    {% 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
5 years ago

Thank you!
This does work!

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
3 94 3 hours ago
Support · by Anna, 3 days ago
2 94 24 hours ago
Support · by Justin Young, 1 day ago
1 64 1 day ago
Support · by Duc , 1 week ago
2 100 6 days ago
Support · by Colin Hume, 1 week ago
2 91 6 days ago