Karmalakas/grav-plugin-translate-date

Does not work with Spanish date

Closed this issue · 5 comments

Hi @Karmalakas.

I'm trying to fix date translations in the Editorial theme and the translation date is not working as expected.
The code I use is this:

{% if config.plugins["translate-date"].enabled %}
     {% set datestamp = (page.header.publish_date) ? (page.header.publish_date|td(null, "Y-m-d")) : (page.date|td(null, "Y-m-d")) %}
.....more code here

{% if datestamp %}
    <time itemprop="datePublished" class="data-post">
        {{'EDITORIAL.ITEM.POSTED_ON'|t}} {{ datestamp }}
    </time>
{% endif %}

But it still shows Publicado el 2023-03-07, in Year-Month-Day format, while I have the plugin configured with m-d-Y.

What can I do? What's wrong?

Maybe I'm missing something, but it looks like you have |td(null, "Y-m-d") in your template, which forces Y-m-d 🤔

Ok. I've removed (null, "Y-m-d") and it works fine.
Previously I've defined the lang variable to {% set lang = grav.language.getActive ?: grav.config.site.default_lang %} and then I've used your plugin in this way: {% set datestamp = (page.header.publish_date) ? (page.header.publish_date|td(lang)) : (page.date|td(lang)) %}

I thought td(null, "Y-m-d") was good for having a default option when the language was not defined in the language.yaml file.

How could I do that of offering the user a default option if their language is not in the languages.yaml file?
Thanks.

|td (lang) should work fine if there's a language in the plugin config 🤔 Sorry, I won't be able to check this for sure myself until the end of September since I'm on vacation

Happy vacations!