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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Dec 19 08:28:10 EST 2008


Author: christoph
Date: 2008-12-19 08:28:10 -0500 (Fri, 19 Dec 2008)
New Revision: 3360

Modified:
   trunk/mapbender/http/classes/class_locale.php
Log:
http://trac.osgeo.org/mapbender/ticket/359

Modified: trunk/mapbender/http/classes/class_locale.php
===================================================================
--- trunk/mapbender/http/classes/class_locale.php	2008-12-19 13:24:19 UTC (rev 3359)
+++ trunk/mapbender/http/classes/class_locale.php	2008-12-19 13:28:10 UTC (rev 3360)
@@ -27,120 +27,124 @@
  *
  */
 class Mb_locale {
-        var $knownLanguages = null;
-        var $systemLocales = null;
-        var $browserLanguages = null;
-        var $os = null;
-        var $name = null;
-        var $defaultLanguage = "en";
-        var $status = "No locale set.";
+	var $knownLanguages = null;
+	var $systemLocales = null;
+	var $browserLanguages = null;
+	var $os = null;
+	var $name = null;
+	var $defaultLanguage = "en";
+	var $status = "No locale set.";
 
-        function Mb_locale($languageId) {
-                if (!$languageId) {
-                        $languageId = LANGUAGE;
-                }
-                  $e = new Mb_notice("class_locale: setting locale to " . $languageId);
-                if (USE_I18N) {
-                        if (!$this->setCurrentLocale($languageId)) {
-                                $e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
-                        }
-                }
-                else {
-                        $this->setCurrentLocale($this->defaultLanguage);
-                }
-        }
+	function Mb_locale($languageId) {
+		if (!$languageId) {
+		        $languageId = LANGUAGE;
+		}
+		$e = new Mb_notice("class_locale: setting locale to " . $languageId);
+		if (USE_I18N) {
+			if (!$this->setCurrentLocale($languageId)) {
+	    	    $e = new Mb_exception("Locale could not be set. Language ID: '" . $languageId . "'");
+			}
+		}
+		else {
+			$this->setCurrentLocale($this->defaultLanguage);
+		}
+	}
 
-        /**
-         * Get the current locale, evaluating GET/POST variables, browser languages
-         * and a default locale (in that preference)
-         *
-         * @returns current locale
-         */
-        function setCurrentLocale($languageId) {
+    /**
+     * Get the current locale, evaluating GET/POST variables, browser languages
+     * and a default locale (in that preference)
+     *
+     * @returns current locale
+     */
+    function setCurrentLocale($languageId) {
 
-                  // try to set the locale to $languageId
-                if ($this->checkAndSetLocale($languageId)) {
-                        return true;
-                  }
-                  else {
-                          $e = new Mb_notice("class_locale: no input parameter specified.");
-                  }
+		// try to set the locale to $languageId
+		if ($this->checkAndSetLocale($languageId)) {
+			return true;
+		}
+		else {
+			$e = new Mb_notice("class_locale: no input parameter specified.");
+		}
+		
+		// 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);
+	}
 
-                // 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;
-                        }
-                }
+	/**
+	* checks if a locale is available; if yes, it is set via setlocale
+	*
+	* @returns true if the the locale is set successfully; otherwise false
+	*/
+	function checkAndSetLocale($languageId) {
+		if ($this->os == null) {
+			$this->os = $this->guessHostOS();
+		}
+		
+		if (!USE_I18N || ($this->os != null && isset($languageId))) {
+			if ($this->isKnownLanguage($languageId)) {
+		
+				if ($this->systemLocales == null) {
+					$this->setSystemLocales();
+				}
+		
+				$locale = $this->systemLocales[$this->knownLanguages[$languageId]][$this->os];
+				$selectedLocale = setlocale(LC_MESSAGES, $locale);
 
-                // set to default language
-                $e = new Mb_notice("trying default language " . $this->defaultLanguage);
-                return $this->checkAndSetLocale($this->defaultLanguage);
-        }
+				if ($selectedLocale) {
+					$this->name = $selectedLocale;
+					$_SESSION["mb_lang"] = $languageId;
+					$_SESSION["mb_locale"] = $this->name;
+					$e = new Mb_notice("locale " . $this->name . " ok on " . $this->os);
 
-        /**
-         * checks if a locale is available; if yes, it is set via setlocale
-         *
-         * @returns true if the the locale is set successfully; otherwise false
-         */
-        function checkAndSetLocale($languageId) {
-                if ($this->os == null) {
-                        $this->os = $this->guessHostOS();
-                }
+					// from http://de3.php.net/manual/de/function.gettext.php
+					$path = bindtextdomain("Mapbender", dirname(__FILE__)."/../../resources/locale/");
+					$enc = bind_textdomain_codeset("Mapbender", "UTF-8");
+					$dom = textdomain("Mapbender");
+					return true;
+				}
+			}
+		}
+		$e = new Mb_notice("locale " . $locale . " not found.");
+		return false;
+	}
 
-                if (!USE_I18N || ($this->os != null && isset($languageId))) {
-                        if ($this->isKnownLanguage($languageId)) {
+	/**
+	* Guess the operating system which on which this code is running
+	* multiple methods are tested for reliably guessing the os
+	*
+	* @private
+	* @returns string with os name
+	*/
+	function guessHostOS(){
+		if (strncasecmp(php_uname(), 'Windows', 7) == 0) {
+			return 'windows';
+		}
+		else if (strncasecmp(php_uname(), 'Linux', 5) == 0) {
+			return 'linux';
+		}
+		else if (strncasecmp(php_uname(), 'OpenBSD', 7) == 0) {
+			return 'bsd';
+		}
+		else if (strncasecmp(php_uname(), 'FreeBSD', 7) == 0) {
+			return 'bsd';
+		}
+		new mb_exception('unknown platform: could not interpret uname. php_uname() returned '. php_uname().'. Please report to MB developers');
+		return null;
+	}
 
-                                if ($this->systemLocales == null) {
-                                        $this->setSystemLocales();
-                                }
-
-                                $locale = $this->systemLocales[$this->knownLanguages[$languageId]][$this->os];
-                                $selectedLocale = setlocale(LC_MESSAGES, $locale);
-                                if ($selectedLocale) {
-                                        $this->name = $selectedLocale;
-                                        $_SESSION["mb_lang"] = $languageId;
-                                        $_SESSION["mb_locale"] = $this->name;
-                                        $e = new Mb_notice("locale " . $this->name . " ok on " . $this->os);
-                                        // from http://de3.php.net/manual/de/function.gettext.php
-                                        $path = bindtextdomain("Mapbender", dirname(__FILE__)."/../../resources/locale/");
-                                        $enc = bind_textdomain_codeset("Mapbender", "UTF-8");
-                                        $dom = textdomain("Mapbender");
-                                        return true;
-                                }
-                        }
-                }
-                $e = new Mb_notice("locale " . $locale . " not found.");
-                return false;
-        }
-
         /**
-         * Guess the operating system which on which this code is running
-         * multiple methods are tested for reliably guessing the os
-         *
-         * @private
-         * @returns string with os name
-         */
-        function guessHostOS(){
-          if (strncasecmp(php_uname(), 'Windows', 7) == 0)
-            return 'windows';
-          else if (strncasecmp(php_uname(), 'Linux', 5) == 0)
-            return 'linux';
-          else if (strncasecmp(php_uname(), 'OpenBSD', 7) == 0)
-            return 'bsd';
-          else if (strncasecmp(php_uname(), 'FreeBSD', 7) == 0)
-            return 'bsd';
-          else {
-            throw new Mb_exception('unknown platform: could not interpret uname. php_uname() returned '. php_uname().'. Please report to MB developers');
-            return null;
-          }
-        }
-
-        /**
          * checks if a language is supported
          *
          * @returns true if the language is supported; otherwise false
@@ -164,40 +168,54 @@
          * determines the available Locales on this system
          */
         function setSystemLocales() {
-                $this->systemLocales['it_IT'] = array('linux' => 'it_IT.utf8',
+                $this->systemLocales['it_IT'] = array(
+										'linux' => 'it_IT.utf8',
                                         'windows' => 'Italian_Italy.1252',
                                         'bsd' => 'it_IT',
                                         'posix' => 'it_IT');
-                $this->systemLocales['de_DE'] = array('linux' => 'de_DE.utf8',
+                $this->systemLocales['de_DE'] = array(
+										'linux' => 'de_DE.utf8',
                                         'windows' => 'German_Germany.1252',
                                         'bsd' => 'de_DE',
                                         'posix' => 'de_DE');
-                $this->systemLocales['en_US'] = array('linux' => 'en_US.utf8',
+                $this->systemLocales['en_US'] = array(
+										'linux' => 'en_US.utf8',
                                         'windows' => 'English_United States.1252',
                                         'bsd' => 'en_US',
                                         'posix' => 'en_US');
+                $this->systemLocales['bg_BG'] = array(
+										'linux' => 'bg_BG.utf8',
+                                        'windows' => 'Bulgarian_Bulgaria.1251',
+                                        'bsd' => 'bg_BG',
+                                        'posix' => 'bg_BG');
+                $this->systemLocales['el_GR'] = array(
+										'linux' => 'el_GR.utf8',
+                                        'windows' => 'Greek_Greece.1253',
+                                        'bsd' => 'el_GR',
+                                        'posix' => 'el_GR');
         }
 
         /**
          * set the known languages
          */
         function setKnownLanguages() {
-                $this->knownLanguages = array('en_US' => 'en_US',
-                      'en' => 'en_US',
-                      'de_DE' => 'de_DE',
-                      'de' => 'de_DE',
-                      'bg_BG' => 'bg_BG',
-                      'bg' => 'bg_BG',
-                      'es_ES' => 'es_ES',
-                      'es' => 'es_ES',
-                      'nl_NL' => 'nl_NL',
-                      'nl' => 'nl_NL',
-					  'fr_FR' => 'fr_FR',
-                      'fr' => 'fr_FR',
-                      'gr_GR' => 'gr_GR',
-                      'gr' => 'gr_GR',
-                      'it_IT' => 'it_IT',
-                      'it' => 'it_IT');
+                $this->knownLanguages = array(
+						'en_US' => 'en_US',
+						'en' => 'en_US',
+						'de_DE' => 'de_DE',
+						'de' => 'de_DE',
+						'bg_BG' => 'bg_BG',
+						'bg' => 'bg_BG',
+						'es_ES' => 'es_ES',
+						'es' => 'es_ES',
+						'nl_NL' => 'nl_NL',
+						'nl' => 'nl_NL',
+						'fr_FR' => 'fr_FR',
+						'fr' => 'fr_FR',
+						'el_GR' => 'el_GR',
+						'gr' => 'el_GR',
+						'it_IT' => 'it_IT',
+						'it' => 'it_IT');
         }
 
         /**



More information about the Mapbender_commits mailing list