[geeklog-cvs] Translator mergeversions,1.1.1.1,1.2 Translator.class.php,1.1.1.1,1.2

tony at iowaoutdoors.org tony at iowaoutdoors.org
Mon Jul 19 17:04:40 EDT 2004


Update of /var/cvs/Translator
In directory www:/tmp/cvs-serv10890

Modified Files:
	mergeversions Translator.class.php 
Log Message:
Initial attempts a making the code PHP5-ready.  Code doesn't yet support notion of <section> tags so it is surely broken.

Index: mergeversions
===================================================================
RCS file: /var/cvs/Translator/mergeversions,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** mergeversions	15 Apr 2003 21:12:45 -0000	1.1.1.1
--- mergeversions	19 Jul 2004 21:04:36 -0000	1.2
***************
*** 1,3 ****
! #!/usr/local/bin/php -q
  <?php
  
--- 1,3 ----
! #!/usr/bin/php -q
  <?php
  
***************
*** 5,18 ****
  * Translations Library - VersionMerge.class.php
  *
! * This source file is subject to version 2.02 of the PHP license,
! * that is bundled with this package in the file LICENSE, and is
! * available at through the world-wide-web at
! * http://www.php.net/license/2_02.txt.
! * If you did not receive a copy of the PHP license and are unable to
! * obtain it through the world-wide-web, please send a note to
! * license at php.net so we can mail you a copy immediately.
  *
! * @author Tony Bibbs <tony AT geeklog DOT net>
! * @copyright Tony Bibbs 2003
  * @package net.geeklog.translations
  * @version $Id$
--- 5,16 ----
  * Translations Library - VersionMerge.class.php
  *
! * This source file is subject to version 2.02 of the PHP license, that is bundled with this package
! * in the file LICENSE, and is available at through the world-wide-web at
! * http://www.php.net/license/2_02.txt. If you did not receive a copy of the PHP license and are
! * unable to obtain it through the world-wide-web, please send a note to license at php.net so we can
! * mail you a copy immediately.
  *
! * @author Tony Bibbs <tony at geeklog.net>
! * @copyright Tony Bibbs 2003-2004
  * @package net.geeklog.translations
  * @version $Id$
***************
*** 21,33 ****
  
  /**
! * Take an outdated XML translation file and merges strings into
! * the new, untranslated XML file.
  *
! * This class makes updating a language file for an application from
! * one version to the next easy by taking the old values and merging them
! * into the new, untranslated XML file.  From there the translator only
! * needs to edit the resulting XML file and add the new strings.
  *
! * @author Tony Bibbs <tony AT geeklog DOT net>
  * @package net.geeklog.translations
  *
--- 19,29 ----
  
  /**
! * Take an outdated XML translation file and merges strings into the new, untranslated XML file.
  *
! * This class makes updating a language file for an application from one version to the next easy by
! * taking the old values and merging them into the new, untranslated XML file.  From there the
! * translator only needs to edit the resulting XML file and add the new strings.
  *
! * @author Tony Bibbs <tony at geeklog.net>
  * @package net.geeklog.translations
  *
***************
*** 38,42 ****
      * @var string
      */
!     var $_oldFile = null;
      
      /**
--- 34,38 ----
      * @var string
      */
!     private $oldFile = null;
      
      /**
***************
*** 44,48 ****
      * @var string
      */
!     var $_newFile = null;
      
      /**
--- 40,44 ----
      * @var string
      */
!     private $newFile = null;
      
      /**
***************
*** 50,54 ****
      * @var string
      */
!     var $_outputFile = null;
      
      /**
--- 46,50 ----
      * @var string
      */
!     private $outputFile = null;
      
      /**
***************
*** 56,60 ****
      * @var object
      */
!     var $_outputFp = null;
      
      /**
--- 52,56 ----
      * @var object
      */
!     private $outputFp = null;
      
      /**
***************
*** 62,66 ****
      * @var array
      */
!     var $_oldStrings = null;
      
      /**
--- 58,62 ----
      * @var array
      */
!     private $oldStrings = null;
      
      /**
***************
*** 68,72 ****
      * @var array
      */
!     var $_newStrings = null;
      
      /**
--- 64,68 ----
      * @var array
      */
!     private $newStrings = null;
      
      /**
***************
*** 74,78 ****
      * @var boolean
      */
!     var $_isOld = null;
      
      /**
--- 70,74 ----
      * @var boolean
      */
!     private $isOld = null;
      
      /**
***************
*** 80,84 ****
      * @var string
      */
!     var $_curElement = null;
      
      /**
--- 76,80 ----
      * @var string
      */
!     private $curElement = null;
      
      /**
***************
*** 86,90 ****
      * @var string
      */
!     var $_curId = null;
  
      /**
--- 82,86 ----
      * @var string
      */
!     private $curId = null;
  
      /**
***************
*** 92,96 ****
      * @var array
      */
!     var $_appName = null;
      
      /**
--- 88,92 ----
      * @var array
      */
!     private $appName = null;
      
      /**
***************
*** 98,102 ****
      * @var array
      */
!     var $_appVersion = null;
      
      /**
--- 94,98 ----
      * @var array
      */
!     private $appVersion = null;
      
      /**
***************
*** 104,108 ****
      * @var array
      */
!     var $_authorName = null;
      
      /**
--- 100,104 ----
      * @var array
      */
!     private $authorName = null;
      
      /**
***************
*** 110,114 ****
      * @var array
      */
!     var $_authorEmail = null;
      
      /**
--- 106,110 ----
      * @var array
      */
!     private $authorEmail = null;
      
      /**
***************
*** 116,120 ****
      * @var array
      */
!     var $_nativeLang = null;
      
      /**
--- 112,116 ----
      * @var array
      */
!     private $nativeLang = null;
      
      /**
***************
*** 127,134 ****
      *
      */
!     function VersionMerge()
      {
!         $this->_oldStrings = array();
!         $this->_newStrings = array();
      }
      
--- 123,130 ----
      *
      */
!     public function __construct()
      {
!         $this->oldStrings = array();
!         $this->newStrings = array();
      }
      
***************
*** 140,152 ****
      *
      */
!     function _addXMLHeaders()
      {
!         fwrite($this->_outputFp,
              sprintf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<APPLICATION name=\"%s\" version=\"%s\">\n    <TRANSLATOR name=\"%s\" email=\"%s\" />\n    <TRANSLATION language=\"%s\">\n",
!             $this->_appName,
!             $this->_appVersion,
!             $this->_authorName,
!             $this->_authorEmail,
!             $this->_nativeLang));
      }
  
--- 136,148 ----
      *
      */
!     private function addXMLHeaders()
      {
!         fwrite($this->outputFp,
              sprintf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<APPLICATION name=\"%s\" version=\"%s\">\n    <TRANSLATOR name=\"%s\" email=\"%s\" />\n    <TRANSLATION language=\"%s\">\n",
!             $this->appName,
!             $this->appVersion,
!             $this->authorName,
!             $this->authorEmail,
!             $this->nativeLang));
      }
  
***************
*** 157,164 ****
      *
      */
!     function _addXMLFooters()
      {
!         fwrite($this->_outputFp,"    </TRANSLATION>\n</APPLICATION>");
!         fclose($this->_outputFp);
      }
      
--- 153,160 ----
      *
      */
!     private function addXMLFooters()
      {
!         fwrite($this->outputFp,"    </TRANSLATION>\n</APPLICATION>");
!         fclose($this->outputFp);
      }
      
***************
*** 172,179 ****
      *
      */
!     function _addString($strId, $translation)
      {
          $translation = htmlspecialchars($translation, ENT_NOQUOTES);
!         fwrite($this->_outputFp,
              sprintf("    <ENTRY>\n        <STRING_ID>%s</STRING_ID>\n        <STRING>%s</STRING>\n    </ENTRY>\n",
              $strId, $translation));
--- 168,175 ----
      *
      */
!     private function addString($strId, $translation)
      {
          $translation = htmlspecialchars($translation, ENT_NOQUOTES);
!         fwrite($this->outputFp,
              sprintf("    <ENTRY>\n        <STRING_ID>%s</STRING_ID>\n        <STRING>%s</STRING>\n    </ENTRY>\n",
              $strId, $translation));
***************
*** 187,191 ****
      *
      */
!     function _getHelp()
      {
          echo "\n--old        Name of your existing translated XML file\n\n";
--- 183,187 ----
      *
      */
!     private function getHelp()
      {
          echo "\n--old        Name of your existing translated XML file\n\n";
***************
*** 208,229 ****
      *
      */
!     function _handleStartElement($parser, $name, $attributes)
      {
!         $this->_curElement = $name;
          
          if ($name == 'APPLICATION') {
!             if (!$this->_isOld) {
!                 $this->_appName = $attributes['NAME'];
!                 $this->_appVersion = $attributes['VERSION'];
              }
          }
          
!         if ($name == 'TRANSLATOR' AND $this->_isOld) {
!             $this->_authorName = $attributes['NAME'];
!             $this->_authorEmail = $attributes['EMAIL'];
          }
          
!         if ($name == 'TRANSLATION' and $this->_isOld) {
!             $this->_nativeLang = $attributes['LANGUAGE'];
          }
      }
--- 204,225 ----
      *
      */
!     private function handleStartElement($parser, $name, $attributes)
      {
!         $this->curElement = $name;
          
          if ($name == 'APPLICATION') {
!             if (!$this->isOld) {
!                 $this->appName = $attributes['NAME'];
!                 $this->appVersion = $attributes['VERSION'];
              }
          }
          
!         if ($name == 'TRANSLATOR' AND $this->isOld) {
!             $this->authorName = $attributes['NAME'];
!             $this->authorEmail = $attributes['EMAIL'];
          }
          
!         if ($name == 'TRANSLATION' and $this->isOld) {
!             $this->nativeLang = $attributes['LANGUAGE'];
          }
      }
***************
*** 240,246 ****
      *
      */
!     function _handleEndElement()
      {
!         $this->_curElement = '';
      }
      
--- 236,242 ----
      *
      */
!     private function handleEndElement()
      {
!         $this->curElement = '';
      }
      
***************
*** 254,275 ****
      *
      */
!     function _handleData($parser, $data)
      {
!         if (empty($this->_curElement)) {
              return;
          }
          
!         switch ($this->_curElement) {
              case 'STRING_ID':
!                 if (!$this->_isOld) {
!                     $this->_newStrings[$data] = '';
                  } else {
!                     $this->_curId = $data;
                  }
                  break;
              case 'STRING':
!                 if ($this->_isOld) {
                      print "Found string: $data\n";
!                     $this->_oldStrings[$this->_curId] = $data;
                  }
                  break;
--- 250,271 ----
      *
      */
!     private function handleData($parser, $data)
      {
!         if (empty($this->curElement)) {
              return;
          }
          
!         switch ($this->curElement) {
              case 'STRING_ID':
!                 if (!$this->isOld) {
!                     $this->newStrings[$data] = '';
                  } else {
!                     $this->curId = $data;
                  }
                  break;
              case 'STRING':
!                 if ($this->isOld) {
                      print "Found string: $data\n";
!                     $this->oldStrings[$this->curId] = $data;
                  }
                  break;
***************
*** 293,297 ****
      *
      */
!     function _replaceSpecialChars($inputString)
      {
          $inputString = str_replace('&','**_amp_**', $inputString);
--- 289,293 ----
      *
      */
!     private function replaceSpecialChars($inputString)
      {
          $inputString = str_replace('&','**_amp_**', $inputString);
***************
*** 314,318 ****
      *
      */
!     function _reinsertSpecialChars($inputString)
      {
          $inputString = str_replace('**_amp_**', '&', $inputString);
--- 310,314 ----
      *
      */
!     private function reinsertSpecialChars($inputString)
      {
          $inputString = str_replace('**_amp_**', '&', $inputString);
***************
*** 326,330 ****
      * Loads the strings for a given language code into memory
      *
!     * @author Tony Bibbs <tony AT geeklog DOT net>
      * @access private
      * @param string $filename Name of file to get strings from
--- 322,326 ----
      * Loads the strings for a given language code into memory
      *
!     * @author Tony Bibbs <tony at geeklog.net>
      * @access private
      * @param string $filename Name of file to get strings from
***************
*** 332,345 ****
      *
      */
!     function _loadStrings($filename, $isOld)
      {
!         $this->_isOld = $isOld;
       
!         if ($this->_isOld) {
              print "\nProcesing old file: $filename\n\n";
          } else {
              print "\nProcessing new file: $filename\n\n";
          }
!         $this->_strings = array();
          
          // Make sure we have a valid translation file
--- 328,341 ----
      *
      */
!     private function loadStrings($filename, $isOld)
      {
!         $this->isOld = $isOld;
       
!         if ($this->isOld) {
              print "\nProcesing old file: $filename\n\n";
          } else {
              print "\nProcessing new file: $filename\n\n";
          }
!         $this->strings = array();
          
          // Make sure we have a valid translation file
***************
*** 355,376 ****
          // should so we need to replace them with a token until we are done processing
          // and them jam them back in.
!         $xmlData = $this->_replaceSpecialChars($xmlData);
          
          // Create Expat parser object
!         $this->_parser = xml_parser_create();
          
          // Lets expat know this class will handle the parsing
!         xml_set_object($this->_parser, &$this);
!         xml_set_element_handler($this->_parser, '_handleStartElement', '_handleEndElement');
!         xml_set_character_data_handler($this->_parser, '_handleData');
          
          // Actually parse the XML now.
!         if (!xml_parse($this->_parser, $xmlData)) {
              trigger_error(sprintf("XML error: %s at line %d",
!                 xml_error_string(xml_get_error_code($this->_parser)),
!                 xml_get_current_line_number($this->_parser)));
              exit;
          }
!         xml_parser_free($this->_parser);
          
          return true;
--- 351,372 ----
          // should so we need to replace them with a token until we are done processing
          // and them jam them back in.
!         $xmlData = $this->replaceSpecialChars($xmlData);
          
          // Create Expat parser object
!         $this->parser = xml_parser_create();
          
          // Lets expat know this class will handle the parsing
!         xml_set_object($this->parser, &$this);
!         xml_set_element_handler($this->parser, '_handleStartElement', '_handleEndElement');
!         xml_set_character_data_handler($this->parser, '_handleData');
          
          // Actually parse the XML now.
!         if (!xml_parse($this->parser, $xmlData)) {
              trigger_error(sprintf("XML error: %s at line %d",
!                 xml_error_string(xml_get_error_code($this->parser)),
!                 xml_get_current_line_number($this->parser)));
              exit;
          }
!         xml_parser_free($this->parser);
          
          return true;
***************
*** 387,391 ****
      *
      */
!     function _handleCommandLineArgs($args)
      {
          $validOptions = array('--old'=>1,'--new'=>1,'--target'=>1);
--- 383,387 ----
      *
      */
!     private function handleCommandLineArgs($args)
      {
          $validOptions = array('--old'=>1,'--new'=>1,'--target'=>1);
***************
*** 395,399 ****
          // all other arguments
          if (in_array('--help',array_keys($args))) {
!             $this->_getHelp();
              exit;
          }
--- 391,395 ----
          // all other arguments
          if (in_array('--help',array_keys($args))) {
!             $this->getHelp();
              exit;
          }
***************
*** 403,407 ****
              if (!in_array(key($args),$optionNames)) {
                  echo "Invalid argument: $curArg\n";
!                 $this->_getHelp();
                  exit;
              }
--- 399,403 ----
              if (!in_array(key($args),$optionNames)) {
                  echo "Invalid argument: $curArg\n";
!                 $this->getHelp();
                  exit;
              }
***************
*** 412,416 ****
              if ($validOptions[$curName] == 1 AND empty($args[$curName])) {
                  echo "Missing required argument: $curName\n";
!                 $this->_getHelp();
                  exit;
              }
--- 408,412 ----
              if ($validOptions[$curName] == 1 AND empty($args[$curName])) {
                  echo "Missing required argument: $curName\n";
!                 $this->getHelp();
                  exit;
              }
***************
*** 420,431 ****
              switch (key($args)) {
                  case '--old':
!                     $this->_loadStrings($curArg, true);
                      break;
                  case '--new':
!                     $this->_loadStrings($curArg, false);
                      break;
                  case '--target':
!                     $this->_outputFile = $curArg;
!                     $this->_outputFp = fopen($this->_outputFile,'w');
                      break;
                  default:
--- 416,427 ----
              switch (key($args)) {
                  case '--old':
!                     $this->loadStrings($curArg, true);
                      break;
                  case '--new':
!                     $this->loadStrings($curArg, false);
                      break;
                  case '--target':
!                     $this->outputFile = $curArg;
!                     $this->outputFp = fopen($this->outputFile,'w');
                      break;
                  default:
***************
*** 448,454 ****
      {
          // Validate arguments and load set-up data
!         $this->_handleCommandLineArgs($args);
!         $this->_addXMLHeaders();
!         $idArray = array_keys($this->_newStrings);
          
          foreach ($idArray as $curId) {
--- 444,450 ----
      {
          // Validate arguments and load set-up data
!         $this->handleCommandLineArgs($args);
!         $this->addXMLHeaders();
!         $idArray = array_keys($this->newStrings);
          
          foreach ($idArray as $curId) {
***************
*** 456,469 ****
              // NOTE: the call to _reinsertSpecialChars is to replace tokens we added in order to
              // allow Expat parser to handle HTML special chars properly
!             if (!empty($this->_oldStrings[$curId])) {
!                 $this->_addString($this->_reinsertSpecialChars($curId), $this->_oldStrings[$curId]);
              } else {
!                 $tmpString = $this->_reinsertSpecialChars($curId);
                  print "Found new string: $tmpString\n";
!                 $this->_addString($this->_reinsertSpecialChars($curId), '');
              }
!             next($this->_newStrings);
          }
!         $this->_addXMLFooters();
      }
      
--- 452,465 ----
              // NOTE: the call to _reinsertSpecialChars is to replace tokens we added in order to
              // allow Expat parser to handle HTML special chars properly
!             if (!empty($this->oldStrings[$curId])) {
!                 $this->addString($this->reinsertSpecialChars($curId), $this->oldStrings[$curId]);
              } else {
!                 $tmpString = $this->reinsertSpecialChars($curId);
                  print "Found new string: $tmpString\n";
!                 $this->addString($this->reinsertSpecialChars($curId), '');
              }
!             next($this->newStrings);
          }
!         $this->addXMLFooters();
      }
      

Index: Translator.class.php
===================================================================
RCS file: /var/cvs/Translator/Translator.class.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Translator.class.php	15 Apr 2003 21:12:45 -0000	1.1.1.1
--- Translator.class.php	19 Jul 2004 21:04:36 -0000	1.2
***************
*** 12,16 ****
  * license at php.net so we can mail you a copy immediately.
  *
! * @author Tony Bibbs <tony AT geeklog DOT net>
  * @copyright Tony Bibbs 2003
  * @package net.geeklog.translations
--- 12,16 ----
  * license at php.net so we can mail you a copy immediately.
  *
! * @author Tony Bibbs <tony at geeklog.net>
  * @copyright Tony Bibbs 2003
  * @package net.geeklog.translations
***************
*** 22,26 ****
  * This class translates English text to the user's desired language
  *
! * @author Tony Bibs <tony AT geeklog DOT net>
  * @package net.geeklog.translations
  *
--- 22,26 ----
  * This class translates English text to the user's desired language
  *
! * @author Tony Bibs <tony at geeklog.net>
  * @package net.geeklog.translations
  *
***************
*** 31,35 ****
      * @var string
      */
!     var $_strings = null;
      
      /**
--- 31,35 ----
      * @var string
      */
!     private $strings = null;
      
      /**
***************
*** 37,41 ****
      * @var string
      */
!     var $_nativeLang = null;
      
      /**
--- 37,41 ----
      * @var string
      */
!     private $nativeLang = null;
      
      /**
***************
*** 43,47 ****
      * @var string
      */
!     var $_userLang = null;
      
      /**
--- 43,47 ----
      * @var string
      */
!     private $userLang = null;
      
      /**
***************
*** 49,53 ****
      * @var string
      */
!     var $_translationDir = null;
      
      /**
--- 49,53 ----
      * @var string
      */
!     private $translationDir = null;
      
      /**
***************
*** 55,59 ****
      * @var string
      */
!     var $_parser = null;
      
      /**
--- 55,59 ----
      * @var string
      */
!     private $parser = null;
      
      /**
***************
*** 61,65 ****
      * @var string
      */
!     var $_curElement = null;
      
      /**
--- 61,65 ----
      * @var string
      */
!     private $curElement = null;
      
      /**
***************
*** 67,71 ****
      * @var string
      */
!     var $_curID = null;
      
      /**
--- 67,71 ----
      * @var string
      */
!     private $curID = null;
      
      /**
***************
*** 76,88 ****
      * doesn't already exist
      *
!     * @author Tony Bibbs <tony AT geeklog DOT net>
      * @access public
      *
      */
!     function Translator($nativeLangCode = 'en')
      {
!         $this->_nativeLang = $nativeLangCode;
!         if (empty($this->_userLang)) {
!             $this->_userLang = $nativeLangCode;
          }
      }
--- 76,88 ----
      * doesn't already exist
      *
!     * @author Tony Bibbs <tony at geeklog.net>
      * @access public
      *
      */
!     function __construct($nativeLangCode = 'en')
      {
!         $this->nativeLang = $nativeLangCode;
!         if (empty($this->userLang)) {
!             $this->userLang = $nativeLangCode;
          }
      }
***************
*** 102,108 ****
      *
      */
!     function _handleStartElement($parser, $name, $attributes)
      {
!         $this->_curElement = $name;
      }
      
--- 102,108 ----
      *
      */
!     private function handleStartElement($parser, $name, $attributes)
      {
!         $this->curElement = $name;
      }
      
***************
*** 118,124 ****
      *
      */
!     function _handleEndElement()
      {
!         $this->_curElement = '';
      }
      
--- 118,124 ----
      *
      */
!     private function handleEndElement()
      {
!         $this->curElement = '';
      }
      
***************
*** 132,147 ****
      *
      */
!     function _handleData($parser, $data)
      {
!         if (empty($this->_curElement) OR !trim($data)) return;
          
          // Grab the native language string from the XML
!         if ($this->_curElement == 'STRING_ID') {
!             $this->_curID = $data;
          }
          
          // OK, store the new translation
!         if ($this->_curElement == 'STRING') {
!             $this->_strings[$this->_curID] = $data;
          }
      }
--- 132,147 ----
      *
      */
!     private function handleData($parser, $data)
      {
!         if (empty($this->curElement) OR !trim($data)) return;
          
          // Grab the native language string from the XML
!         if ($this->curElement == 'STRING_ID') {
!             $this->curID = $data;
          }
          
          // OK, store the new translation
!         if ($this->curElement == 'STRING') {
!             $this->strings[$this->curID] = $data;
          }
      }
***************
*** 150,163 ****
      * Loads the strings for a given language code into memory
      *
!     * @author Tony Bibbs <tony AT geeklog DOT net>
      * @access private
      *
      */
!     function _loadStrings()
      {
!         $this->_strings = array();
          
          // Make sure we have a valid translation file
!         $filename = $this->_translationDir . $this->_userLang . '.xml';
          if (!file_exists($filename)) {
              trigger_error('Bad translation file in Translator::_loadStrings');
--- 150,163 ----
      * Loads the strings for a given language code into memory
      *
!     * @author Tony Bibbs <tony at geeklog.net>
      * @access private
      *
      */
!     private function loadStrings()
      {
!         $this->strings = array();
          
          // Make sure we have a valid translation file
!         $filename = $this->translationDir . $this->userLang . '.xml';
          if (!file_exists($filename)) {
              trigger_error('Bad translation file in Translator::_loadStrings');
***************
*** 169,187 ****
          
          // Create Expat parser object
!         $this->_parser = xml_parser_create();
          
          // Lets expat know this class will handle the parsing
!         xml_set_object($this->_parser, &$this);
!         xml_set_element_handler($this->_parser, '_handleStartElement', '_handleEndElement');
!         xml_set_character_data_handler($this->_parser, '_handleData');
          
          // Actually parse the XML now.
!         if (!xml_parse($this->_parser, $xmlData)) {
              trigger_error(sprintf("XML error: %s at line %d",
!                 xml_error_string(xml_get_error_code($this->_parser)),
!                 xml_get_current_line_number($this->_parser)));
              exit;
          }
!         xml_parser_free($this->_parser);
          
          return true;
--- 169,187 ----
          
          // Create Expat parser object
!         $this->parser = xmlparser_create();
          
          // Lets expat know this class will handle the parsing
!         xml_set_object($this->parser, &$this);
!         xml_set_element_handler($this->parser, '_handleStartElement', '_handleEndElement');
!         xml_set_character_data_handler($this->parser, '_handleData');
          
          // Actually parse the XML now.
!         if (!xml_parse($this->parser, $xmlData)) {
              trigger_error(sprintf("XML error: %s at line %d",
!                 xml_error_string(xml_get_error_code($this->parser)),
!                 xml_get_current_line_number($this->parser)));
              exit;
          }
!         xmlparser_free($this->parser);
          
          return true;
***************
*** 195,212 ****
      * request.
      *
!     * @author Tony Bibbs <tony AT geeklog DOT net>
      * @access public
      * @param string $langCode Language to translate strings to
      *
      */
!     function setUserLanguage($langCode = '')
      {
          // Default the user language to the native
          // language if none was provided
          if (empty($langCode)) {
!             $langCode = $this->_nativeLang;
          }
          
!         $this->_userLang = $langCode;
      }
      
--- 195,212 ----
      * request.
      *
!     * @author Tony Bibbs <tony at geeklog.net>
      * @access public
      * @param string $langCode Language to translate strings to
      *
      */
!     public function setUserLanguage($langCode = '')
      {
          // Default the user language to the native
          // language if none was provided
          if (empty($langCode)) {
!             $langCode = $this->nativeLang;
          }
          
!         $this->userLang = $langCode;
      }
      
***************
*** 220,227 ****
      *
      */
!     function setTranslationDir($path)
      {
          if (is_dir($path)) {
!             $this->_translationDir = $path;
          }
      }
--- 220,227 ----
      *
      */
!     public function setTranslationDir($path)
      {
          if (is_dir($path)) {
!             $this->translationDir = $path;
          }
      }
***************
*** 237,251 ****
      * string passed to this method.
      *
!     * @author Tony Bibbs <tony AT geeklog DOT net>
      * @access public
!     * @param string $originalText Text in _nativeLang language
      * @return string Translated text
      *
      */
!     function translate($originalText)
      {
          // Of course if they are asking for native language then we are
          // already done.
!         if ($this->_userLang == $this->_nativeLang) {
              return $originalText;
          }
--- 237,251 ----
      * string passed to this method.
      *
!     * @author Tony Bibbs <tony at geeklog.net>
      * @access public
!     * @param string $originalText Text in nativeLang language
      * @return string Translated text
      *
      */
!     public function translate($originalText)
      {
          // Of course if they are asking for native language then we are
          // already done.
!         if ($this->userLang == $this->nativeLang) {
              return $originalText;
          }
***************
*** 253,257 ****
              return $originalText;
          }
!         return $this->_strings[$originalText];
      }
  }
\ No newline at end of file
--- 253,257 ----
              return $originalText;
          }
!         return $this->strings[$originalText];
      }
  }
\ No newline at end of file




More information about the geeklog-cvs mailing list