1

I want to set the correct locale to receive the correct translation for dates and time.

I tried:

$locale = setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');

but this won't work. I already googled and what I found didn't help in my case. I tried changing LC_ALL to LC_TIME but it has no effect.

If I execute locale -a in the shell, i receive:

C C.UTF-8 POSIX de_DE.utf8

I also took a look in /etc/default/locale

LANG="de_DE.UTF-8"

In php.ini the timezone is also set to Europe/Berlin.
So what the heck am I doing wrong? On my local machine with EasyPhp it works fine.

To get the localized next month i use strftime:

 $nextMonth = explode(" ", strftime( '%m %B %Y', strtotime( '+1 month', $date ) ));

Instead of

Juni

I always receive

June

I tried other languages as well, but no difference.

I use php7.1 if it matters.

EDIT: I already found this post PHP setlocale has no effect but nothing worked for me.

Community
  • 1
  • 1
Ronon
  • 738
  • 10
  • 26
  • Just to re-iterate: You **did** try `setlocale(LC_ALL, "de_DE.utf8");` ? What's its return value? – ccKep May 14 '17 at 18:53
  • Also: Did you just install that locale? If so: Did you restart your httpd after doing so? – ccKep May 14 '17 at 18:56
  • I tried it with it, yes. I also restarted nginx and php several times. But without any changes. I just restarted the server just in case and now it's working. Weird behavior. – Ronon May 14 '17 at 20:20

1 Answers1

1

Don't be fooled by the ".utf8" part of the locale. Setlocale is for single byte functions only, they don't work well with Unicode. Also, it matters which operating system you are using, and depending on the operating system, it matters if you use the TS or NTS build of PHP.

For internationalisation / Unicode I'd recommend using the Intl extention, it has full Unicode support and a very complete calendar IntlCalendar.

Code4R7
  • 2,600
  • 1
  • 19
  • 42