Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP setlocale not working even with locales existing

Tags:

php

setlocale

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!

like image 826
kambythet Avatar asked Oct 13 '13 23:10

kambythet


1 Answers

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, "");
like image 88
kambythet Avatar answered Oct 05 '22 21:10

kambythet