0

Possible Duplicate:
PHP Date function output in Italian

I try to FORCE local to change and get the value of date outputt in french... this dont work : here is the code

setlocale(LC_ALL, 'ca_FR');
echo date("l, F d, Y");

here is the server setting : PHP Version >= 5.2 (5.2.16+ best) 5.2.17 and Operating System : Linux

I need to output the date in french as : mercredi.....

Community
  • 1
  • 1
menardmam
  • 9,860
  • 28
  • 85
  • 113

3 Answers3

6

From the manual:

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

So use:

setlocale(LC_ALL, 'ca_FR');
echo strftime("%A, %e %B, %G");

note: the selected locale must also be installed on the server, so check if ca_FR is a installed locale. A lot of linux systems have fr_FR or fr_FR.utf8 as french locale

Lusitanian
  • 11,012
  • 1
  • 41
  • 38
JvdBerg
  • 21,777
  • 8
  • 38
  • 55
  • strftime uses different formatting, so `"l, F d, Y"` (which works with `date()`) doesn't do what you want it to. `setlocale(LC_ALL, 'fr_CA'); echo strftime("%A, %e %B, %G");` – Frank Farmer Oct 03 '12 at 21:27
1

Try using strftime() instead of date(): strftime documentation

Kyriog
  • 828
  • 1
  • 8
  • 13
1

here is the final working code

//Add a SHORTCODE to get date listing
add_shortcode ('getdate','get_date_listing');
   function get_date_listing ($att) {

    $outputtvar = '';

    // set the default timezone to use. Available since PHP 5.1
    date_default_timezone_set('America/Montreal');

    //ID of the post containing DATE LIST
    $req_id = 901;
    $post = get_page($req_id); 
    $content = apply_filters('the_content', $post->post_content);

    // Strip all <p> tags
    $content = str_replace( "<p>", "", $content );

    // Replace </p> with a known delimiter
    $content = str_replace( "</p>", "|", $content );

    //Separate de dates
    $contentarray = explode( '|', $content );

    //remove the last empty date
    unset($contentarray[count($contentarray)-1]);

    if (qtrans_getLanguage() == 'fr') { setlocale(LC_ALL, 'fr_CA'); $datesetting = "%A, %e %B, %G"; } 
    if (qtrans_getLanguage() == 'en') { setlocale(LC_ALL, 'en_US'); $datesetting = "%A, %B %e, %G";} 

    //prepare the outputt
    $outputtvar .= '<ul>';

    foreach ($contentarray as $key => $value) {
        $timestamp = strtotime($value);
        $localdate = strftime($datesetting,$timestamp);
        $localdate = utf8_encode($localdate);
        $outputtvar .= '<li>' . $localdate . '</li>';
    }

    $outputtvar .= '</ul>';

    return $outputtvar ;

   } 
menardmam
  • 9,860
  • 28
  • 85
  • 113