# HG changeset patch # User Matti Hamalainen # Date 1351036450 -10800 # Node ID 6635246b70d9fc7011ce731b2f9ca3d37d6b2273 # Parent ee2d16f9b20471a7d4e1723ea9c9beae3ef35830 Implement translations. diff -r ee2d16f9b204 -r 6635246b70d9 index.php --- a/index.php Wed Oct 24 02:53:44 2012 +0300 +++ b/index.php Wed Oct 24 02:54:10 2012 +0300 @@ -4,45 +4,116 @@ // $pageCharset = "utf-8"; $internalCharset = "utf-8"; -$luokkaDefault = "TTE9SNO"; +$classDefault = "TTE9SNO"; $classFile = "luokat.txt"; $cacheFile = "coursecache.txt"; -$baseURI = "http://tnsp.org/luk2/"; +$baseURI = "http://tnsp.org/luk/"; //$infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&opas=2010-2011&vuosi=10S11K&koodi1="; $infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&koodi1="; -$dayNames = array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"); $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk"); $pageCSSAlts = array("blue" => "1", "old" => "2", "purple" => "3"); +$pageLanguages = array("fi", "en"); + +$lukDayNames = array( + "fi" => array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai"), + "en" => array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), +); + +$lukTranslations = array( + "Original" => array("fi" => "Alkuperäinen"), + "Next period" => array("fi" => "Seuraava periodi"), + "Current period" => array("fi" => "Nykyinen periodi"), + "Switch" => array("fi" => "Vaihda"), + + "contact" => array( + "en" => "Contact ccr @ IRCNet tai ccr at tnsp dot org. The author can't be held responsible for any errors in the data!", + "fi" => "Yhteydenotot ccr @ IRCNet tai ccr at tnsp dot org. En vastaa mahdollisista virheistä tiedoissa!", + ), + + "beta" => array( + "en" => " NOTICE! Lukkari v2.0beta is not yet finished. Features present in the previous version but currently missing (mini-mode) will return soon.", + "fi" => " HUOM! Lukkari v2.0beta on vielä keskeneräinen. Vanhassa versiossa olleet puuttuvat ominaisuudet (mini-moodi) palaavat piakkoin.", + ), + + "viikossa" => array( + "en" => "Total of %1 hours in the week.", + "fi" => "Viikossa yhteensä %1 tuntia.", + ), + + "classNotSet" => array( + "en" => "Class not set, using default %1.", + "fi" => "Luokkaa ei asetettu, käytetään vakioarvoa %1.", + ), + + "Style" => array("fi" => "Tyyli"), +// "" => array("fi" => ), +); + + // Include framework require "mcommon.inc.php"; require "merrors.inc.php"; -// Helper functions +// Translation function +function lukMsg($msg) +{ + global $lukTranslations, $pageLang; + + if (!isset($pageLang)) + $pageLang = "fi"; + + if (isset($lukTranslations[$msg]) && isset($lukTranslations[$msg][$pageLang])) + $str = $lukTranslations[$msg][$pageLang]; + else + $str = $msg; + + foreach (func_get_args() as $argn => $argv) + { + $str = preg_replace("/\%".$argn."/", $argv, $str); + } + return $str; +} + + +function lukGetDayName($day) +{ + global $lukDayNames, $pageLang; + + if (!isset($pageLang)) + $pageLang = "fi"; + + if (isset($lukDayNames[$pageLang]) && isset($lukDayNames[$pageLang][$day])) + return $lukDayNames[$pageLang][$day]; + else + return $lukDayNames["en"][$day]; +} + + function lukChEntities($str) { global $internalCharset; -// return $str; return htmlentities($str, ENT_NOQUOTES, $internalCharset); } + function lukCheckClassID(&$id) { - global $luokkaDefault; + global $classDefault; if (preg_match("#^([A-Z]{3}\d[A-Za-z0-9_]{1,6}|ccr|Ryh_[A-Z]{3}\d[A-Za-z0-9_]{1,6})$#", $id, $m)) { $id = $m[1]; return TRUE; } else { - errorMsg("Virhe! Luokan täytyy olla muotoa XXXnXXX, käytetään vakioarvoa ".$luokkaDefault."."); - $id = $luokkaDefault; + errorMsg("Virhe! Luokan täytyy olla muotoa XXXnXXX, käytetään vakioarvoa ".$classDefault."."); + $id = $classDefault; return FALSE; } } -function lukGetDayFromTimestamp($stamp) +function lukGetWeekdayFromTimestamp($stamp) { $info = getdate($stamp); $day = $info["wday"]; @@ -169,9 +240,6 @@ } -// Check for mini-info mode -$miniMode = isset($_GET["nyt"]); - // Check given parameters if (isset($_GET["luokka"])) { @@ -189,11 +257,30 @@ } else { - errorMsg("Luokkaa ei asetettu, käytetään vakioarvoa ".$luokkaDefault."."); - $luokka = $luokkaDefault; + errorMsg(lukMsg("classNotSet", $classDefault)); + $luokka = $classDefault; } +if (isset($_GET["lang"])) +{ + $tmp = strtolower($_GET["lang"]); + if (in_array($tmp, $pageLanguages)) + { + $pageLang = $tmp; + setcookie("luklang", $tmp, time() + 365*24*60*60); // expire in a year + } +} +else +if (isset($_COOKIE["luklang"])) +{ + $tmp = $_COOKIE["luklang"]; + if (in_array($tmp, $pageLanguages)) + $pageLang = $tmp; +} + + + if (isset($_GET["next"])) { $nextPeriod = TRUE; @@ -262,24 +349,24 @@ function lukNormalTimeTable() { - global $classInfo, $classHourDefs, $dayNames, $classHourTimes; + global $classInfo, $classHourDefs, $classHourTimes; // $currStamp = time() + 9 * 60 * 60 + 18 * 60; $currStamp = time(); $currTime = $currStamp - mktime(0, 0, 0); - $currDay = lukGetDayFromTimestamp($currStamp); + $currDay = lukGetWeekdayFromTimestamp($currStamp); // Create the timetable table $out = "

".join("; ", $classInfo["general"])."

\n". - "
Viikossa yhteensä ".$classInfo["totalHours"]." tuntia.
\n". + "
".lukMsg("viikossa", $classInfo["totalHours"])."
\n". "". " \n \n"; $cellWidth = 100 / $classInfo["maxDays"]; if ($cellWidth > 25) $cellWidth = 25; for ($day = 0; $day < $classInfo["maxDays"]; $day++) { - $out .= " \n"; + $out .= " \n"; } $out .= " \n"; @@ -304,12 +391,7 @@ $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; $out .= " \n"; } @@ -345,18 +427,11 @@ echo " - - + -if ($miniMode) - echo "\">Normaali"; -else - echo "&nyt\">Mini-info"; - -echo " - - - +
".$dayNames[$day]."".lukGetDayName($day)."
"; - -// if ($isActive) -// $out .= sprintf("%d : %d <> %d, %d -- ", $day, $currTime, $classHourTimes[$class["start"]]["start"], $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]); - - $out .= + "\" class=\"".($class["grouped"] ? "clgrouped" : ($isActive ? "clactive" : "clnormal"))."\">". lukGetClassInfo($isSplit, $class["data"]). "
".$class["hours"]."h
".lukMsg("Original")."Alkuperäinen".($nextPeriod ? "Nykyinen" : "Seuraava")." periodi". + ($nextPeriod ? lukMsg("Current period") : lukMsg("Next period"))."
@@ -378,16 +453,26 @@ echo lukNormalTimeTable(); } -echo "
-Yhteydenotot ccr @ IRCNet tai ccr at tnsp dot org. En vastaa mahdollisista virheistä tiedoissa! +echo "
". +lukMsg("contact"). +"". +lukMsg("beta"). +"
Lukkari v2.0 beta
-Style: "; +
".lukMsg("Style").": "; + foreach ($pageCSSAlts as $name => $id) echo "".$name.""; + +echo "
"; +foreach ($pageLanguages as $id) + echo "".$id.""; + echo "
+
"; printPageFooter();