[TwentyFifteen] Post date translation

My translated TwentyFifteen theme shows the following date format in the footer of a post:

Lipiec July 29th at 5:10pm

“Lipiec” is a Polish translation of July, so the template renders my translation from the languages.yaml file, as well as the standard date format.

I suspect the problem is in the following section of the blog.item.html.twig file:

<footer class="entry-footer">
        <span class="posted-on">
            <time class="entry-date published updated" datetime="{{ page.date|date(config.system.pages.dateformat.short) }}">{{ 'MONTHS_OF_THE_YEAR'|ta(page.date|date('n') - 1) }} {{ page.date|date(config.system.pages.dateformat.default) }}</time> 

… but do not know Twig at all, so cannot say what’s wrong.

It seems that this section renders a default date format if the short format is larger than some kind of a filter on MONTHS_OF_THE_YEAR? This does not make sense, so I am probably reading it in a wrong way.

Also, assuming it can be fixed easily… how do I put the updated class as inherited Twig code in a child theme? Do I copy the entire blog.item.html.twig file to the child theme folder, edit the problematic class and comment out the rest?

Here’s the docs on theme inheritance. You create a child theme, copy the offending file over, and edit it as you see fit. The one in your child theme will be used instead of the default.

The list of Grav filters is also in the docs. ta is the translate filter. So it’s printing out the translated month and then the full date, apparently not localized.

There’s a Twig Extensions plugin that includes an all-in-one date localizer.

Hi @Perlkonig,

thank you!

Any advice how I can localize the full date manually - i.e., what to add to the languages.yaml file?

    TITLE: Mój blog
    DESCRIPTION: Blog o wszystkim
    COPYRIGHT: © Copyright by Author, Year.
  SUBSCRIBE: Subskrypcja
  MONTHS_OF_THE_YEAR: [Styczeń, Luty, Marzec, Kwiecień, Maj, Czerwiec, Lipiec, Sierpień, Wrzesień, Październik, Listopad, Grudzień]
  DAYS_OF_THE_WEEK: [Poniedziałek, Wtorek, Środa, Czwartek, Piątek, Sobota, Niedziela]
  READ_MORE: Czytaj dalej
  RANDOM_ARTICLE: Losowy artykuł
  RELATED_POSTS: Powiązane artykuły
  ARCHIVES: Archiwum
  POPULAR_TAGS: Popularne tagi
  PUBLISHED_BY: Opublikowany przez
  PREVIOUS: Poprzedni
  NEXT: Następny
  PAGE: Strona

With my level of technical undesrtanding the Twig Extensions plugin seems more complex than manual localization - although thank you for pointing the plugin out!

It’s super simple! The demo site shows you how.

Just install the plugin and then run your date through the localizeddate filter.

It’s good to learn Twig eventually :slight_smile:

1 Like

It is simple :slight_smile: I guess I needed a fresh look.

Also, this is covered in Twig Recipes - Displaying a Translated Month.

Your responses, the documentation and a couple of searches on Twig’s date and localizeddate filters let me get it done.