PHP setlocale has no effect

toesslab picture toesslab · Jun 6, 2012 · Viewed 93k times · Source

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

Answer

Benjamin Seiller picture Benjamin Seiller · Jun 6, 2012

Is 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

locale -a

to see which locales are installed. Also have a look here Is it feasible to rely on setlocale, and rely on locales being installed?