Jump to content




Recent Status Updates

View All Updates

Binpress - Cut your development time and costs in half
- - - - -

Translate date into your language


  • This topic is locked This topic is locked
6 replies to this topic

#1 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 29 May 2007 - 12:38 PM

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.

<?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 ^^


// 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..


// 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:

echo $daynum.". ", $month." ", $day." ", $year;


Simple eh.. :D okay here's the full script:

<?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;
?>

Edited by Roger, 04 January 2011 - 08:26 PM.

  • 0

#2 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 31 May 2007 - 07:23 AM

Nice tutorial, thanks for the post Jaan.
  • 0

#3 v0id

v0id

    Retired

  • Retired Mod
  • PipPipPipPipPipPipPipPip
  • 2,313 posts

Posted 31 May 2007 - 07:39 AM

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:
<?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!
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#4 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 31 May 2007 - 09:01 AM

thank you :)
  • 0

#5 John

John

    CC Mentor

  • Moderator
  • 4,450 posts
  • Location:New York, NY

Posted 31 May 2007 - 03:19 PM

I would prefer using a switch-statement, instead of if-statements.


Thats the exact same thing I told him :D but either way works
  • 0

#6 Guest_Jaan_*

Guest_Jaan_*
  • Guest

Posted 01 June 2007 - 02:23 PM

yes you did.. ^^ but still.. i like elseif thingy :D
  • 0

#7 Roger

Roger

    Skadoosh!

  • Administrator
  • 1,209 posts
  • Programming Language:C, PHP
  • Learning:Others

Posted 04 January 2011 - 08:26 PM

The original poster is no longer active on CodeCall. If you have any question regarding this posting, please start a new thread in the appropriate forum (and reference this thread).

Thank you.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?
Factoid: Most questions asked on this forum have been previously answered, if you search you may find the answer.




Powered by binpress