Translating date formats

Yes, otherwise it doesn’t work.

What does that mean?

Well that’s where my mistake was. I absolutely had to use strftime and not the date one. Thanks a lot for your patience!

Hello! I’m struggling with a similar issue but have followed exact steps and am still not sure why my dates are always in English for my multilanguage site.

In my config.php file,

<?php

return [
    'debug'  => true,
    'languages' => true,
    'language.detect' => true,

    'date'  => [
        'handler' => 'strftime'
    ]
];

In my nl.php file,

<?php

return [
  'code' => 'nl',
  'direction' => 'ltr',
  'locale' => [
    'LC_ALL' => 'nl_NL.utf8',
    'LC_TIME' => 'nl_NL.utf8'
  ],
  'name' => 'Nederlands'

];

Here I’ve tried ‘nl_NL’ and ‘nl_NL.ISO8859-15’ and it doesn’t work either.

In my en.php file,

<?php

return [
  'code' => 'en',
  'default' => true,
  'direction' => 'ltr',
  'locale' => [
    'LC_ALL' => 'en_US'
  ],
  'name' => 'English'

];

And in my php template,

<?= $event->startdate()->toDate('%a %d %B') ?>

I still see “Mon 07 March” on both the English and Dutch versions of the site. Is there something else I might be missing?

Have you verified the exact locales installed on your system with locale -a(Mac/Linux).

On my Mac, for example, 'nl_NL.UTF-8works, butnl_NL.utf8` wouldn’t.

You can use

locale -a | grep 'nl_'

to only list the ones starting with nl.

On my system, this command would return

nl_NL.UTF-8
nl_BE
nl_BE.ISO8859-15
nl_NL.ISO8859-15
nl_NL
nl_BE.UTF-8
nl_NL.ISO8859-1
nl_BE.ISO8859-1

Hmm yes I did this as well, I also get the following:

nl_NL.UTF-8
nl_BE
nl_BE.ISO8859-15
nl_NL.ISO8859-15
nl_NL
nl_BE.UTF-8
nl_NL.ISO8859-1
nl_BE.ISO8859-1

So you’re right, but when I changed it to ‘nl_NL.UTF-8’ it still didn’t change the language. Is there something else it could be related to?

I also saw from the php docs that strftime will be deprecated in PHP 8.1.0, but I’m using PHP 7.4.21, so that shouldn’t be the case either…

Deprecated doesn’t mean it won’t work anymore in 8.1, but it won’t have a future after that.

Are you running this locally? In which development environment?

Ahh yes it’s possibly related to the fact that I’m running this locally. I’m using MAMP with an Apache web server running on PHP 7.4.21. Is there something else I could do to test the language settings?

It should work locally as well. Make sure that Opcache is disabled, it’s enabled by default in recent versions of MAMP it seems.

Ah is this a screenshot from MAMP Pro?

I’m using regular MAMP, it looks like PHP-cache is off:

I also tried setting opcache.revalidate_freq=0 in the relevant php.ini file and still don’t see the language changing… maybe I’ll try an alternate development environment and see if it helps…

Hardly dare asking, but are you actually in the right language on the frontend?

Haha I don’t blame you, I am also wondering what’s left that I might be overlooking! Do you mean if I’m actually looking at the ‘nl’ version of the site url?

I mean, it is the first time I’m setting up a multilanguage site, so perhaps there is something obvious I didn’t know about. But I’m switching between the two languages and still see the same date in English, even if the rest of the content is in Dutch…

Also just tested it on a live server and it looks to still be showing just the date in English on both language versions of the website.

Can’t figure out what else could be causing this…

Are you using the latest Kirby version, i.e. 3.6.2?

Yes!

Can you actually reproduce the error in a fresh Starterkit to which you add your configuration just like I did in my test?

Which test are you referring to?

I just downloaded a fresh copy of Startkit and tried adjusting to the same settings and still see English on both language sites… so I must be doing something wrong…

To elaborate, I did the following steps in order:

  1. In config.php, added 'languages' => true
  2. Created the default English and secondary Dutch language options under ‘Languages’
  3. Back in config.php, added 'date' => [ 'handler' => 'strftime' ]
  4. Made a small change in the note.php template:
<time class="note-date" datetime="<?= $page->date('c') ?>">Published on <?= $page->date()->toDate('%a %d %B') ?></time>
  1. Opened the page in a browser and it still shows the English date on both language sites :confused:

In the Starterkit, you have to pass the format to date(), i.e. without adding the toDate() field method to the date field:

Published on <?= $page->date('%a %d %B') ?>

because it is using a page model for the date (to confuse newcomers at bit :wink:)

Ahh I see! That could be it :slight_smile:

But the output is then “2020-12-10 16:00:00”. Is there something else I need to add to the formatting to make it print “Thu 10 December”?

Ah, sorry, my bad, forget what I wrote above, your code was actually right, I confused it with the published() method that is used in the notes page overview.

I’m actually at my wits end and don’t know what else to check. If you like, you can send me a PM with a link to your project, then I can test in my environment.