Karmalakas / grav-plugin-translate-date

Define date formats for each language and easily use for dates in your templates
MIT License
7 stars 5 forks source link

Does not work with Spanish date #18

Closed pmoreno-rodriguez closed 11 months ago

pmoreno-rodriguez commented 1 year ago

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?

Karmalakas commented 1 year ago

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

pmoreno-rodriguez commented 1 year ago

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)) %}

pmoreno-rodriguez commented 1 year ago

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.

Karmalakas commented 1 year ago

|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

pmoreno-rodriguez commented 1 year ago

Happy vacations!