PHP setlocale not working even with locales existing

kambythet picture kambythet · Oct 14, 2013 · Viewed 18.3k times · Source

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!

Answer

kambythet picture kambythet · Oct 14, 2013

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, "");