The setlocale()
function doesn't set the desired language (German).
The goal is to output month names.
This is my test code with trials so far:
<?php
date_default_timezone_set('Europe/Berlin');
setlocale(LC_ALL, 'de_DE.utf8');
// Or
setlocale(LC_ALL, 'de_DE@euro');
// Or
setlocale(LC_ALL, 'de_DE');
// Or
setlocale(LC_ALL, 'de');
// Or
setlocale(LC_ALL, 'ge');
echo strftime('%B');
Output:
June
instead of
Juni
Any suggestions?
- I don't have ssh or other shell access.
- The script is running on a linux server.
PHP version 5.6
Depending on the underlying OS
"de_DE"
and others maybe the wrong string.Under Windows refer this lists:
Usually it's "DEU" or "GERMAN" under Win.
Already mentioned:
Under Linux you can see all locales with the shell command:
For those coming here looking for date() doesn't localize month and weekday names:
== Pay Attention ==
date() is only able to return month/day names in English and won't be able to give you translations for other languages.
Thanks to Rico Neitzel for the hint. Instead of trying to format php date, use strftime. To see the first 3 letters of month name in your language (Ex. Dez instead of Dec from Dezembro and not December), follow the locale instalation instructions above, and then:
date command: date('d M Y')// impossible to change from EnglishIs is quite likely that the German locale is not installed on the server your running the script on - do you have shell access to the server? Then try
to see which locales are installed. Also have a look here Is it feasible to rely on setlocale, and rely on locales being installed?
If your are on a Red Hat machine you can run :
Then restart your Apache server
This solution might help if you don't have shell access to the server.
If you have shell access, then Benjamin Seiller's answer is the best!
As I don't have any other possibilities (shell), I've found a solution with only PHP by using the IntlDateFormatter class.