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

Quark theme: Dates are not translated

Solved by Pedro M View solution

Started by Martin 3 years ago · 8 replies · 450 views
3 years ago

I am currently trying Grav and have a problem with untranslated dates. I have set "de" as the (only) supported language. Dates, for example in the articles or in the archives plugin are still displayed to me as English date (see screenshot). Is this a known problem or have I perhaps overlooked a setting?
grav-quark-dates|690x294

3 years ago

@beedaddy, Have you had a chance to search the forum? Try searching for: translate date

3 years ago

Yes, I did, but as a beginner I could not find a solution. Sometimes the modification of template files is recommended. I could not imagine that this is actually necessary, since it is a standard case. I assumed an error or a wrong configuration. Apparently I was wrong and a more extensive intervention is necessary to get a date translated...

3 years ago

@beedaddy,

I assumed an error or a wrong configuration. Apparently I was wrong and a more extensive intervention is necessary to get a date translated…

Unfortunately, it does indeed require a bit more work...

3 years ago Solution

Hi @beedaddy
You can try something like this in partials/blog/date.html.twig:

TWIG
{# Support for translate and twig extensions plugins #}
{% set lang = grav.language.getActive ?: grav.config.site.default_lang %}
{% if config.plugins["translate-date"].enabled %}
    {% set datestamp = (page.header.publish_date) ? (page.header.publish_date|td(null, "m-d-Y")) : (page.date|td(null, "m-d-Y")) %}
{% elseif config.plugins["twig-extensions"].enabled %}
    {% set datestamp = (page.header.publish_date) ? (page.header.publish_date|localizeddate('medium', 'none', lang)) : (page.date|localizeddate('medium', 'none', lang)) %}
{% else %}
    {% set datestamp = (page.header.publish_date) ? (page.header.publish_date|date(system.pages.dateformat.short)) : (page.date|date(system.pages.dateformat.short)) %}
{% endif %}

{% if datestamp %}
<span class="blog-date">
    <time class="dt-published" datetime="{{ datestamp }}">
        <i class="fa fa-calendar"></i> {{ datestamp }}
    </time>
</span>
{% endif %}

For this to work properly you must set a language in the site settings (settings/languages) and have one of the two plugins referenced in the code installed: translate-date or twig-extensions.

👍 1
last edited 07/12/23 by Pedro M
3 years ago

Hi @pmoreno
Sorry for the stupid question, but: do I have to edit the file directly or can/should it be copied to somewhere and then modified? Question is regarding future updates…

3 years ago

Thanks a lot!
The problem with the publish dates is resolved. And I guess I have to do something similar with plugins/archives/templates/partials/archives.html.twig?

3 years ago

You just have to copy archives.html.twig from the plugin to your partials folder of your child theme and make the necessary modifications there

👍 1

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 195 2 months ago
Themes & Styling · by Ian, 2 months ago
3 91 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 451 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 45 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 125 3 months ago