setlocale having no effect in PHP

Do you have the de locale available; what does setlocale return for you? See: return values for setlocale().

Also, check the list of available locales (e.g. locale -a or whatever is suitable for your OS) to see if de is among them. Likely alternatives include de_DE or de_DE.utf8 to name a few.

In Debian, to generate a new locale, run this command:

dpkg-reconfigure locales

and pick the ones you want.


Setting the locale will have no effect if the locale is not installed on your system.


I am using Ubuntu on Raspberry Pi, had the same issue trying to use Portuguese local for date:

setlocale(LC_TIME, "C");
echo strftime("%A");
echo setlocale(LC_TIME, "pt_PT");
echo strftime(" in Portuguese %A");

Then checked with command local -a, pt_PT was not on the list, so I added it sudo /usr/share/locales/install-language-pack pt_PT and run local -a again: there it was pt_PT.utf8. After this, result still the same: output expected for pt_PT still in English. Here is the slight difference that made things work to me:

···
echo setlocale(LC_TIME, "pt_PT.utf8");
···

So, I had to turn pt_PT into pt_PT.utf8

Tags:

Php

Locale