0

Maybe I'm overlooking something here, but I can't find a way to translate the week day names.

This is my template code:

{% set storeHours = storeHoursGlob.storeHours.getRange(1) %}

<div class="p-8 xl:container mx-auto">
    <h3>Openingstijden</h3>
    <div class="grid grid-cols-7">
    {% for day in storeHours %}
        <div class="flex flex-col bg-white">
            <h2 class="text-[#339F7F]">{{ day.name }}</h2>
            <dd>
            {% if day.isBlank %}
                Gesloten
            {% else %}
                {{ day.open|date('H:i') }} - {{ day.close|date('H:i') }}
            {% endif %}
            </dd>
        </div>
    {% endfor %}
    </div>
</div>

Anyone who can point me in the right direction? Thank you very much in advance!

2
  • What exactly is storeHoursGlob?
    – Ben Croker
    Aug 2 at 11:43
  • Maybe Glob = global? Aug 2 at 13:35

1 Answer 1

0

Looks like you're using the Store Hours plugin, right? If you check the source code, you can see that the name property is already returned as a localized day name by default:

return Craft::$app->getLocale()->getWeekDayName($this->dayIndex, $length);

So you probably don't need to do anything, the weekday name will be translated to the current site's language automatically.

If this doesn't work for you or you need to translate the day name to a different language for some reason, you can access the public dayIndex property of the DayData object directly. This will be an integer between 0-6, you can use that to use getWeekDayName function with the locale you want to translate to. Or use built-in functions:

{{ day.dateIndex|date('l') }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.