11

ISSUE RESOLVED (see below)

I have generated the locales on my server, I have confirmed that they exist (my locale -a provided below), but when I use:

    setlocale(LC_TIME,'fr_FR');
    or setlocale(LC_TIME,'fr_FR.utf8');

it doesn't work at all.

Sample:

    <?php
    setlocale(LC_TIME,'fr_FR.utf8');
    echo 'locale - '.setlocale(LC_TIME,'0');
    echo ' : month - '.strftime('%B');
    echo '<br />';

    setlocale(LC_TIME,'fr_FR');
    echo 'locale - '.setlocale(LC_TIME,'0');
    echo ' : month - '.strftime('%B');
    echo '<br />';

    setlocale(LC_TIME,'fr-FR');
    echo 'locale - '.setlocale(LC_TIME,'0');
    echo ' : month - '.strftime('%B');
    echo '<br />';

    setlocale(LC_TIME,'fr');
    echo 'locale - '.setlocale(LC_TIME,'0');
    echo ' : month - '.strftime('%B');
    echo '<br />';

    setlocale(LC_TIME,'french');
    echo 'locale - '.setlocale(LC_TIME,'0');
    echo ' : month - '.strftime('%B');
    echo '<br />';
    ?>

Results:

    locale - C : month - October
    locale - C : month - October
    locale - C : month - October
    locale - C : month - October
    locale - C : month - October

locale -a (showing the fr locales):

    fr_BE.utf8
    fr_CA.utf8
    fr_CH.utf8
    fr_FR.utf8
    fr_LU.utf8

Thank you for the help!

Martin
  • 22,212
  • 11
  • 70
  • 132
kambythet
  • 716
  • 2
  • 9
  • 20

3 Answers3

12

okay, after posting this, I tried one more thing. So for those experiencing the same issue, you need to set this first before setting the new locale:

setlocale(LC_TIME, "");
benomatis
  • 5,536
  • 7
  • 36
  • 59
kambythet
  • 716
  • 2
  • 9
  • 20
  • 2
    Check to make sure you have the locales installed and available on your server. They have to exist in order to use them. `locale -a` – kambythet Apr 24 '14 at 17:22
  • That somehow worked for me, but I'd like to know why? (PS: Accept your own anser `:)`) – user2019515 May 12 '14 at 02:29
  • 1
    If locale is NULL or the empty string "", the locale names will be set from the values of environment variables with the same names as the above categories, or from "LANG". http://php.net/setlocale – kambythet May 12 '14 at 06:01
4

You have to restart php before use new installed locales.

John
  • 737
  • 5
  • 13
1

If you want to use the system default locale in Apache2, you just need to add (or uncomment) the following line in the /etc/apache2/envvars file :

. /etc/default/locale

Think to restart apache2 after this operation and clear your potential cache to check locale is well given to PHP.

lenybernard
  • 2,399
  • 22
  • 22