Long Date Language Translator

Updated diafol 0 Tallied Votes 250 Views Share

A simple example of date (day and month) translation. The code is for Welsh, but can be easily modified for any language - especially those without "full" support. I have used the code in a footer to display the last updated date and time.

//EDIT - a few years later
Please excuse this snippet - it was written when I was starting out and I thought that I could programme :(
There are many, many better ways of doing this.

<?php
function english_to_welsh_date(){
    global $MyDay;
    global $MyMon;

    $day_array = array("Sunday" => "Dydd Sul", "Monday" => "Dydd Llun", "Tuesday" => "Dydd Mawrth", "Wednesday" => "Dydd Mercher", "Thursday" => "Dydd Iau", "Friday" => "Dydd Gwener", "Saturday" => "Dydd Sadwrn");

    $MyDay = $day_array[$MyDay];
    
    $mon_array = array("January" => "Ionawr", "February" => "Chwefror", "March" => "Mawrth", "April" => "Ebrill", "May" => "Mai", "June" => "Mehefin", "July" => "Gorffennaf", "August" => "Awst", "September" => "Medi", "October" => "Hydref", "November" => "Tachwedd", "December" => "Rhagfyr");

    $MyMon = $mon_array[$MyMon];
}


$MyDay = date("l", getlastmod());
$MyMon = date("F", getlastmod());

english_to_welsh_date();
	
$MyDate = "Cyfddyddiwyd: " . $MyDay . ", " . $MyMon . date (" d, Y", getlastmod()) . " am " . date("H:i:s.", getlastmod());

echo $MyDate;

//Displays:- Cyfdyddiwyd: Dydd Mawrth, Hydref 24, 2006 am 15:51:32. for Updated: Tuesday, October 24, 2006 at 15:51:32.
?>
42south 0 Newbie Poster

I have just registered to say 'This is great'!

With very little thinking required on my part, I have managed to successfully adapt it Te Reo (aka Maori)

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.