SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Romuba's Avatar
    Join Date
    Jun 2007
    Location
    Cape Town, South Africa
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Ca I change rendered language?

    I have been using the folowing script for some years and it works perfectly in English but I now need to use this script on a German website and would like to know if there is a way of changing the language the browser displays so that the date portion is in German or French or whatever?

    PHP Code:
    <p>&copy; &lt;?php<br />
      
    ini_set('date.timezone''Africa/Johannesburg');<br />$startYear 2007;<br /> $thisYear date('Y');<br /> if ($startYear == $thisYear) {<br /> echo $startYear;<br /> }<br /> else {<br /> echo "{$startYear}-{$thisYear}";<br /> }<br />
      ?&
    gtBartwebsites  All Rights Reserved.</p>
    <
    p>&lt;?php echo strftime('%A, %d %B %Y'); ?&gt;</p
    Ross Bartholomew
    Web Designer/Developer
    BartWebSites
    E-mail: ross@bartwebsites.com

  2. #2
    SitePoint Addict Romuba's Avatar
    Join Date
    Jun 2007
    Location
    Cape Town, South Africa
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have done more digging and come up with this code but it still isn't working:

    PHP Code:
    <?php

    setlocale
    (LC_TIME"de_DE");
    echo 
    utf8_encode(strftime('%A, %d %B %Y'));

    ?>
    I am working on my localhost using:
    PHP - 5.3.8
    Apache - 2.2.21
    MySQL - 5.5.16
    Ross Bartholomew
    Web Designer/Developer
    BartWebSites
    E-mail: ross@bartwebsites.com

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hi Ross.

    setlocale returns false if it cannot set the locale (possibly because the system doesn't have that locale installed), try the following which works this end.

    Code PHP:
    <?php
    error_reporting(-1);
    ini_set('display_errors', true);
    ini_set('date.timezone', 'Africa/Johannesburg');
     
     
    if( ! setlocale(LC_TIME, 'de_DE')){
        echo 'Cannot set new locale';
        exit;
    }
     
     
    echo strftime('%A %e %B %Y');
    /*
        Donnerstag  5 Januar 2012
    */
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Addict Romuba's Avatar
    Join Date
    Jun 2007
    Location
    Cape Town, South Africa
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that, it shows Cannot set new locale

    How can I install more locales so that I will see the correct rendering?
    Ross Bartholomew
    Web Designer/Developer
    BartWebSites
    E-mail: ross@bartwebsites.com

  5. #5
    SitePoint Addict Romuba's Avatar
    Join Date
    Jun 2007
    Location
    Cape Town, South Africa
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know how to solve this problem?

    I need to be able to have the current date show in English and French on a multi-lingual website. It must display in the format - Monday, 14 March 2012.
    Ross Bartholomew
    Web Designer/Developer
    BartWebSites
    E-mail: ross@bartwebsites.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •