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.

Themes & Styling

[TwentyFifteen] Post date translation

Solved by Aaron Dalton View solution

Started by Radoslaw 8 years ago · 4 replies · 1241 views
8 years ago

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:

TWIG
<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> 
        </span>

... 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?

last edited 07/29/18 by Radoslaw
8 years ago Solution

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.

8 years ago

Hi @Perlkonig,

thank you!

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

YAML
pl:
  SITE:
    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
  SYNDICATE: Kanały RSS
  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!

8 years ago

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 🙂

👍 1

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 197 2 months ago
Themes & Styling · by Ian, 2 months ago
3 92 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 454 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 47 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 127 3 months ago