Locale date formatting

Hello !

I’m trying to format date to French with Kirby, but I can’t make it work :slightly_frowning_face:.
In my config file I have :

'date.handler' => 'strftime',
'locale'       => ['LC_ALL' => 'fr_FR.utf-8'],

And in my template :

$article->date()->toDate('%e %B %Y')

But it doesn’t work.

Also, is it possible to avoid using strftime ? Because it’s marked as deprecated in PHP doc :

Thanks :grinning:

Yes, I wouldn’t use strftime anymore, either.

You can use the intl date formatter instead, but it currently has a bug. You will find a workaround by @rasteiner in the issue as well, though: 'intl' date handler outputs random translation on multilanguage site · Issue #4304 · getkirby/kirby · GitHub

Ok ok i will try this thanks a lot :+1:

Hi again, I just tried to use “intl” but it doesn’t work.
In config file :

'date.handler' => 'intl',
'locale'       => 'fr_FR.utf-8',

In template :

<?= $page->date()->toDate('Y') ?>

I have the following error :

But i tried with the following “vanilla” php and it works :

		$fmt = datefmt_create("en_US", IntlDateFormatter::FULL, IntlDateFormatter::FULL,
			'America/Los_Angeles', IntlDateFormatter::GREGORIAN);
		echo "Le premier format affiché est ".datefmt_format($fmt, 0);

Also, I don’t really understand what does this line do in config.php:

'locale'       => 'fr_FR.utf-8',

It never changes anything, no matter what its value.

Thanks :grinning:

'intl' support was introduced in kirby 3.6.5. You probably have an older version.

The locale setting shouldn’t have any effect on the IntlDateFormatter, that config option is there to switch locales for other functions (like strftime). If you don’t use any of those (not sure, but there may be some stuff like “number formatting” , etc), you don’t need that setting. Anyway, the string has to match a locale that is installed in your OS; you can normally get a list of those by running the command locale -a in a shell.

I was using Kirby 3.6.4 ah ah. Well thanks a lot, it works perfectly. And also ty for the explanation of ‘locale’ setting. :grinning: