+ Reply to Thread
Results 1 to 6 of 6

Thread: Translate date into your language

  1. #1
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,043
    Blog Entries
    9

    Translate date into your language

    Hey!

    Want to know how you can translate date into your language. It's really simple tho.. oki let's start.

    First we have to define our day, month and year.

    Code:
    <?php
    $day 
    date("l");
    $daynum date("j");
    $month date("M");
    $year date("Y");
    ?>
    Now let's translate our days. I'm going to translate our date into estonian

    Code:
    // If our day is Monday (For example) then it changes our day into Esmaspäev (Monday in estonian)
    if($day == "Monday"){
    $day "Esmaspäev";
    }elseif(
    $day == "Tuesday"){
    $day "Teisipäev";
    }elseif(
    $day == "Wednesday"){
    $day "Kolmapäev";
    }elseif(
    $day == "Thursday"){
    $day "Neljapäev";
    }elseif(
    $day == "Friday"){
    $day "Reede";
    }elseif(
    $day == "Saturday"){
    $day "Laupäev";
    }elseif(
    $day == "Sunday"){
    $day "Pühapäev";

    You should change those estonian words into your language
    Now let's translate our months..

    Code:
    // For example..if our month is January then it changes January into Jaanuar
    if($month == "January"){
    $month "Jaanuar";
    }elseif(
    $month == "February"){
    $month "Veebruar";
    }elseif(
    $month == "March"){
    $month "Märts";
    }elseif(
    $month == "April"){
    $month "Aprill";
    }elseif(
    $month == "May"){
    $month "Mai";
    }elseif(
    $month == "June"){
    $month "Juuni";
    }elseif(
    $month == "July"){
    $month "Juuli";
    }elseif(
    $month == "August"){
    $month "August";
    }elseif(
    $month == "September"){
    $month "September";
    }elseif(
    $month == "October"){
    $month "Oktoober";
    }elseif(
    $month == "November"){
    $month "November";
    }elseif(
    $month == "December"){
    $month "Detsember";

    And now let's display our date:

    Code:
    echo $daynum.". "$month." "$day." "$year
    Simple eh.. okay here's the full script:

    Code:
    <?php
    $day 
    date("l");
    $daynum date("j");
    $month date("M");
    $year date("Y");

    if(
    $day == "Monday"){
    $day "Esmaspäev";
    }elseif(
    $day == "Tuesday"){
    $day "Teisipäev";
    }elseif(
    $day == "Wednesday"){
    $day "Kolmapäev";
    }elseif(
    $day == "Thursday"){
    $day "Neljapäev";
    }elseif(
    $day == "Friday"){
    $day "Reede";
    }elseif(
    $day == "Saturday"){
    $day "Laupäev";
    }elseif(
    $day == "Sunday"){
    $day "Pühapäev";
    }

    if(
    $month == "January"){
    $month "Jaanuar";
    }elseif(
    $month == "February"){
    $month "Veebruar";
    }elseif(
    $month == "March"){
    $month "Märts";
    }elseif(
    $month == "April"){
    $month "Aprill";
    }elseif(
    $month == "May"){
    $month "Mai";
    }elseif(
    $month == "June"){
    $month "Juuni";
    }elseif(
    $month == "July"){
    $month "Juuli";
    }elseif(
    $month == "August"){
    $month "August";
    }elseif(
    $month == "September"){
    $month "September";
    }elseif(
    $month == "October"){
    $month "Oktoober";
    }elseif(
    $month == "November"){
    $month "November";
    }elseif(
    $month == "December"){
    $month "Detsember";
    }

    echo 
    $daynum.". "$month." "$day." "$year;
    ?>

    Have fun!
    Jaan
    Last edited by Jaan; 10-06-2007 at 07:36 AM.
    Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us
    CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance

  2. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97
    Nice tutorial, thanks for the post Jaan.

  3. #3
    Retired v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light
    Join Date
    Apr 2007
    Posts
    2,978
    Blog Entries
    3
    I would prefer using a switch-statement, instead of if-statements.
    It's in my opinion cleaner, and neater - but it's all about taste.
    The result is the same, using any of them.

    I've made a danish version, using a switch-statement, just to show how it could look like:
    Code:
    <?php
    $day    = date("l");
    $daynum = date("j");
    $month  = date("M");
    $year   = date("Y");
    
    switch($day)
    {
    	case "Monday":    $day = "Mandag";  break;
    	case "Tuesday":   $day = "Tirsdag"; break;
    	case "Wednesday": $day = "Onsdag";  break;
    	case "Thursday":  $day = "Torsdag"; break;
    	case "Friday":    $day = "Fredag";  break;
    	case "Saturday":  $day = "Lørdag";  break;
    	case "Sunday":    $day = "Søndag";  break;
    	default:          $day = "Unknown"; break;
    }
    
    switch($month)
    {
    	case "January":   $month = "Januar";    break;
    	case "February":  $month = "Februar";   break;
    	case "March":     $month = "Marts";     break;
    	case "April":     $month = "April";     break;
    	case "May":       $month = "Maj";       break;
    	case "June":      $month = "Juni";      break;
    	case "July":      $month = "Juli";      break;
    	case "August":    $month = "August";    break;
    	case "September": $month = "September"; break;
    	case "October":   $month = "Oktober";   break;
    	case "November":  $month = "November";  break;
    	case "December":  $month = "December";  break;
    	default:          $month = "Unknown";   break;
    }
    
    echo $day . " den " . $daynum . ". " . $month . ", " . $year;
    ?>
    Anyways, nice job, Jaan!

  4. #4
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,043
    Blog Entries
    9
    thank you
    Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us
    CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance

  5. #5
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,882
    Blog Entries
    25
    Quote Originally Posted by v0id View Post
    I would prefer using a switch-statement, instead of if-statements.
    Thats the exact same thing I told him but either way works

  6. #6
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,043
    Blog Entries
    9
    yes you did.. but still.. i like elseif thingy
    Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us
    CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. new C-like programming language
    By kenna in forum Software Development Tools
    Replies: 14
    Last Post: 09-03-2008, 02:34 PM
  2. Date in Oracle 8
    By Ronin in forum Database & Database Programming
    Replies: 6
    Last Post: 08-17-2007, 12:25 AM
  3. D Programming Language.
    By R-G in forum General Programming
    Replies: 2
    Last Post: 04-12-2007, 11:22 AM
  4. PHP:Tutorial The Date
    By John in forum PHP Tutorials
    Replies: 0
    Last Post: 01-10-2007, 06:10 PM
  5. What language to Learn?
    By mevets in forum General Programming
    Replies: 20
    Last Post: 12-20-2006, 09:04 AM

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