4

I'm doing this:

{# Get events from `events` section in desired sort order #}
{% set allEvents = craft.entries.section('events').order('eventsDate asc') %}

{# Loop through `allEvents` and print the list #}
{% for event in allEvents %}
    <li>{{ event.title }} - {{ event.eventsDate|date('j F, Y') }}</li>
{% endfor %}

I guess I can do something with this: http://php.net/manual/en/datetime.formats.date.php, but I need to display months in my native language, which is slightly different from how Craft outputs it.

For example I'd like it to say "7 des", not "07 dec", "15 mai", not "15th may" and so on.

3
  • Sorry for the closing, Oyvind. Didn't read your question properly enough and thought Marion is right, that you will find an answer in that other Q/A. Voted to reopen this!
    – carlcs
    Commented Jul 15, 2014 at 19:06
  • Which primary locale (language) did you choose during the installation?
    – carlcs
    Commented Jul 15, 2014 at 19:30
  • My Craft installation is english. Its better that way, when reading documentation and so on. The only language tweak I need to do is for how months is printed. :)
    – osh
    Commented Jul 15, 2014 at 20:24

2 Answers 2

3

Yes, the date() filter you use (see Twig docs) allows you to format dates with the same formating characters as the php date function takes. All language dependent parts are returned in the language of the current locale. I don't know if you can change that primary locale in the control panel, but you could do that in the DB.

As you noted in the comments to your question, you want the CP to be in english. This is possible even if you set the site's locale to another language; the site's locale and the user language for the CP are different things.

3
  • I guess I should give it a try then. How do I set the site's locale to another language without doing any harm?
    – osh
    Commented Jul 16, 2014 at 6:26
  • @Oyvind as I wrote, I think the only way to change the primary locale is to do it in the database directly ('craft-locales' table → 'locale' column). Change this to your desired front-end locale (eg. 'it' with all lowercase).
    – carlcs
    Commented Jul 16, 2014 at 11:33
  • Cheers, that worked fine for me. Commented Dec 5, 2014 at 16:28
1

I think Multilingual Dates where date format varies pretty much covers it.

For details on date formats you will want to look at php's date format documentation

1
  • I'm not using Craft multilangual though. Its just a tweak for this one thing. So, the post 'Multilingual Dates where date format varies' doesn't help me much.
    – osh
    Commented Jul 15, 2014 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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