[pLog-svn] r4797 - plog/branches/lifetype-1.2/class/locale

oscar at devel.lifetype.net oscar at devel.lifetype.net
Tue Feb 20 18:24:56 EST 2007


Author: oscar
Date: 2007-02-20 18:24:55 -0500 (Tue, 20 Feb 2007)
New Revision: 4797

Modified:
   plog/branches/lifetype-1.2/class/locale/locale.class.php
Log:
Minor optimization.

Modified: plog/branches/lifetype-1.2/class/locale/locale.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/locale/locale.class.php	2007-02-20 23:18:44 UTC (rev 4796)
+++ plog/branches/lifetype-1.2/class/locale/locale.class.php	2007-02-20 23:24:55 UTC (rev 4797)
@@ -86,6 +86,7 @@
 		var $_description;
 		var $_dateFormat;
 		var $_firstDayOfWeek;
+		var $_dataLoaded;
 
         /**
          * Constructor.
@@ -99,8 +100,6 @@
          */
 		function Locale( $code )
 		{
-            
-
             $this->_code = $code;
 
             $this->_loadLocaleInfo();
@@ -108,6 +107,7 @@
             if( $this->_charset == "" )
                 $this->_charset = DEFAULT_ENCODING;
 
+			$this->_dataLoaded = false;
 		}
 
         /**
@@ -124,11 +124,12 @@
 
 			// The following is just to handle the case where there isn't
 			// a valid local file.
-			if ( !isset($messages) || !is_array( $messages ) )
-			{
+			if ( !isset($messages) || !is_array( $messages ) ) {
 				$messages = array();
 			}
 			$this->_messages = $messages;
+			
+			$this->_dataLoaded = true;
 
             unset($messages);
 		}
@@ -223,31 +224,6 @@
 			$this->_loadLocaleFile();
 		}
 
-        /**
-         * Translates a string
-         *
-         * @param id Identifier of the message we would like to translate
-         */
-		function getString( $id )
-		{
-			// load the file if it hadn't been loaded yet
-			if( !is_array($this->_messages) ) {
-				$this->_loadLocaleFile();
-            }
-				
-            if( is_array($this->_messages) && array_key_exists($id, $this->_messages) &&
-                $this->_messages[ $id ] != "" ) {
-			    $string = $this->_messages[ $id ];
-            } else {
-            	$string = $id;
-            }
-				
-			/*if( $this->getDirection() == "rtl" )
-				$string = "<span dir=\"rtl\">$string</span>";*/
-
-			return $string;
-		}
-		
 		/**
 		 * returns all the strings
 		 *
@@ -263,12 +239,21 @@
 		}
 
         /**
-         * Alias for getString
-         * @see getString
+         * Translates a string
+         *
+         * @param id Identifier of the message we would like to translate
          */
 		function tr( $id )
 		{
-			return $this->getString( $id );
+			// load the file if it hasn't been loaded yet
+			if( !$this->_dataLoaded ) {
+				$this->_loadLocaleFile();
+            }
+
+			isset( $this->_messages[$id] ) ? $string = $this->_messages[$id] : $string = $id;
+			if( $string == "" ) $string = $id;
+
+			return $string;
 		}
 
         /**



More information about the pLog-svn mailing list