Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP setlocale doesn't work

I try to set the locale from fr_FR to us_US in PHP (php-fpm) with nginX on my raspberry-pi.
Here is my code:

<?php

system('locale -a');
/*
C POSIX en_US.utf8 fr_FR fr_FR.iso88591 fr_FR.iso885915@euro fr_FR.utf8
So the en_US locale is well installed
*/

echo locale_get_default();
/* fr_FR */
echo setlocale(LC_ALL, '0');
/*
LC_CTYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;
LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;
LC_MEASUREMENT=C;LC_IDENTIFICATION=C
*/

var_dump(setlocale(LC_ALL, 'en_US.UTF-8', 'en_US.UTF8'));
/* bool(false) */

var_dump(setlocale(LC_ALL, 'fr_FR.UTF8'));
/* string(10) "fr_FR.UTF8"
useless, but it shows that setlocale works with the already set locale */
?>

I don't understand why setlocale returns false.
It seems something doesn't work but I don't manage to find what.

like image 939
Nicolas Avatar asked Jul 10 '13 09:07

Nicolas


1 Answers

I had the same problem after installing additional locales on debian machine running nginx with php5-fpm

To fix the problem I had to restart php5-fpm.

like image 92
remy Avatar answered Sep 28 '22 03:09

remy