[Mapbender-commits] r1581 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Aug 6 03:54:10 EDT 2007


Author: christoph
Date: 2007-08-06 03:54:10 -0400 (Mon, 06 Aug 2007)
New Revision: 1581

Modified:
   trunk/mapbender/http/classes/class_locale.php
Log:
added comments, exception handling, parameter validation

Modified: trunk/mapbender/http/classes/class_locale.php
===================================================================
--- trunk/mapbender/http/classes/class_locale.php	2007-08-06 07:52:51 UTC (rev 1580)
+++ trunk/mapbender/http/classes/class_locale.php	2007-08-06 07:54:10 UTC (rev 1581)
@@ -20,6 +20,13 @@
 include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
 require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
 
+/**
+ * sets the locale, depending on various settings:
+ * 1) a language ID passed to the constructor
+ * 2) the browser settings $_SERVER["HTTP_ACCEPT_LANGUAGE"]
+ * 3) a default language ID
+ * 
+ */
 class Mb_locale {
 	var $knownLanguages = null;
 	var $systemLocales = null;
@@ -31,7 +38,7 @@
 	
 	function Mb_locale($languageId) {
 		if (!$this->setCurrentLocale($languageId)) {
-			$e = new Mb_exception("Locale with language ID " . $languageId . " could not be set.");
+			$e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
 		}
 	}
 
@@ -44,25 +51,26 @@
 	function setCurrentLocale($languageId) {
 
 	  	// try to set the locale to $languageId
-	  	if (isset($languageId)) {
-			if ($this->checkAndSetLocale($languageId)) {
-				return true;
-			}
+		if ($this->checkAndSetLocale($languageId)) {
+			return true;
 	  	}
+	  	else {
+	  		$e = new Mb_notice("class_locale: no input parameter specified.");
+	  	}
 
-		// TODO: try to set to user settings
-		
 		// determine the browser setting and try to set locale according to that
 		if ($this->browserLanguage == null) {
 			$this->setBrowserLanguages();
 		}		
 		foreach ($this->browserLanguages as $lang) {
+			$e = new Mb_notice("trying browser setting " . $lang);
 			if ($this->checkAndSetLocale($lang)) {
 				return true;
 			}
 		}	
 		
 		// set to default language
+		$e = new Mb_notice("trying default language " . $this->defaultLanguage);
 		return $this->checkAndSetLocale($this->defaultLanguage);
 	}
 	
@@ -76,20 +84,25 @@
 			$this->os = $this->guessHostOS();
 		}
 		
-		if ($this->os != null) {
+		if ($this->os != null && isset($languageId)) {
 			if ($this->isKnownLanguage($languageId)) {
 				
 				if ($this->systemLocales == null) {
 					$this->setSystemLocales();					
 				}
-					
+				
 				$locale = $this->systemLocales[$this->knownLanguages[$languageId]][$this->os];				
+				bindtextdomain(LOCALE_DOMAIN, LOCALE_DIR);
+				textdomain(LOCALE_DOMAIN);
 				if (setlocale(LC_ALL, $locale)) {
 					$this->name = $locale;
+					$_SESSION["mb_lang"] = $languageId;
+					$_SESSION["mb_locale"] = $this->name;
 					$e = new Mb_notice("locale " . $this->name . " ok on " . $this->os);
 					return true;
 				}
 				$e = new Mb_notice("locale " . $locale . " not found.");
+
 			}
 		}
 		return false;
@@ -124,7 +137,13 @@
 		if ($this->knownLocales == null) {
 			$this->setKnownLanguages();
 		}
-		return array_key_exists($languageId, $this->knownLanguages);
+		if (array_key_exists($languageId, $this->knownLanguages)) {
+			return true;
+		}
+		else {
+			$e = new Mb_notice("language " . $languageId . " not supported.");
+		}	
+		return false; 
 	}
 	
 



More information about the Mapbender_commits mailing list