Jump to content

[SOLVED] After update to PHP 8.2, DateTime field would not output german date anymore


nurkka
 Share

Recommended Posts

Hi all!

After I upgraded a site to PHP 8.2, the output of a german month name from a ProcessWire DateTime field didn't work anymore. It always output e.g. "July" instead of "Juli".

I tried to set the locale in config.php by adding setlocale(LC_ALL, 'de_DE.UTF-8'); but that didn't change anything.

As strftime is deprecated in modern PHP versions, I had to add the following code to output the date correctly in german:

			<?php
			$formatter = new \IntlDateFormatter( 'de_DE', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE);
			$formatter->setPattern('d. MMMM yyyy');
			$formatted_date = $formatter->format( $page->getUnformatted('cb_date') );
			?>
			<p class="cb_news_date"><?= $formatted_date ?></p>

Please note that I did not install a german language pack because I wanted to omit the overhead of installing and handling the language modules.

I tried to find IntlDateFormatter within /wire/, but obviously ProcessWire generates the month names in another way.

I also tried to overwrite "July" with "Juli" in the WireDateTime class (for test purposes), but the month name did not change.

How does ProcessWire generate the datetime output and why does it not regard the current locale anymore?
Is the ProcessWire way to do solve this, to install language support and translate text strings? But if they are not in WireDateTime.php, as I have tested, where are they located instead?

 

Link to comment
Share on other sites

Hi, check this: https://github.com/processwire/processwire-issues/issues/1774#issuecomment-1618267798

EDIT:  

5 hours ago, nurkka said:

Please note that I did not install a german language pack because I wanted to omit the overhead of installing and handling the language modules.

I missed that, my answer considers that you are using PW language management.

 

Edited by da²
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

You are completely right. Since strftime() is no longer a thing in PHP> 8.1, ProcessWire no longer uses it to format it's dates. Quickly skipping through the code, you can find that Ryan introduced a replacement for strftime() which uses date() and then translates the language-dependent parts using the PW translation system.

Here's the section in question:

https://github.com/processwire/processwire/blob/3cc76cc886a49313b4bfb9a1a904bd88d11b7cb7/wire/core/WireDateTime.php#L476

Remember, to get gettext-style translations working, you don't need any other modules activated than the LanguageSupport module itself. No need for PageNames and all the others. You can then just add a translation file for the WireDateTime class and translate the months, short months and days to German and you're done.

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

  • nurkka changed the title to [SOLVED] After update to PHP 8.2, DateTime field would not output german date anymore

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...