My problem in short: I am using setlocale(LC_TIME, "de_DE")
in order to display the "verbal" parts of a date/time (i.e. month, weekday) in German. This works on any public server, but doesn't on my localhost, using MAMP, which displays it in English.
I have the following code (nothing else in the file, I reduced it to the minimum necessary to reproduce the issue):
<?php
setlocale(LC_TIME, "de_DE");
date_default_timezone_set('Europe/Berlin');
?>
<!DOCTYPE html>
<html lang='de_DE'>
<head>
<title>Datum in Deutsch</title>
<meta charset="UTF-8">
</head>
<body>
<p>
<?php
echo "Heute ist ";
echo strftime("%A, der %e. %B %Y");
?>
</p>
</body>
</html>
This should be displayed as
Heute ist Donnerstag, der 10. Juni 2021
But on my localhost/MAMP, it is displayed as
Heute ist Thursday, der 10. June 2021
As I mentioned: If I upload this file to any public server and open it, it is displayed as desired (i.e. with the German expressions)
I have searched SO and other websites for a solution. An advice I found several times was to check if the German locale is installed at all on my system.
So I opened the terminal (I am on MacOS 10.14.6) and typed "locale -a": The list of returned and installed locales includes de_DE
(among many others).
I also found the advice to include this line in the code to check whether the desired locale is available, which I did:
<?php echo setlocale(LC_ALL, 0); ?>
This outputs "C/C/C/C/de_DE/C " , so again, de_DE
is included (but won't give me a localized date display).
My system: MacOS 10.14.6, MAMP 6.3 as local Apache server, running PHP 7.4.12 (switching to PHP 8.0 changes nothing)
What can I do to make it work? Any advice appreciated!
source https://stackoverflow.com/questions/67927006/setlocale-not-working-as-expected-on-localhost-mamp-macos
No comments:
Post a Comment