24 #require_once 'Zend/Locale.php'; 27 #require_once 'Zend/Translate/Adapter.php'; 30 #require_once 'Zend/Xml/Security.php'; 33 #require_once 'Zend/Xml/Exception.php'; 43 private $_file =
false;
44 private $_cleared = array();
45 private $_transunit =
null;
46 private $_source =
null;
47 private $_target =
null;
48 private $_scontent =
null;
49 private $_tcontent =
null;
50 private $_stag =
false;
51 private $_ttag =
true;
52 private $_data = array();
66 $this->_data = array();
68 #require_once 'Zend/Translate/Exception.php'; 72 $this->_target = $locale; 74 $encoding = $this->_findEncoding($filename); 75 $this->_file = xml_parser_create($encoding); 76 xml_set_object($this->_file, $this); 77 xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); 78 xml_set_element_handler($this->_file, "_startElement", "_endElement"); 79 xml_set_character_data_handler($this->_file, "_contentElement"); 82 Zend_Xml_Security::scanFile($filename); 83 } catch (Zend_Xml_Exception $e) { 84 #require_once 'Zend/Translate/Exception.php
'; 85 throw new Zend_Translate_Exception( 90 if (!xml_parse($this->_file, file_get_contents($filename))) { 91 $ex = sprintf('XML error: %s at line %d of file %s
', 92 xml_error_string(xml_get_error_code($this->_file)), 93 xml_get_current_line_number($this->_file), 95 xml_parser_free($this->_file); 96 #require_once 'Zend/Translate/Exception.php
'; 97 throw new Zend_Translate_Exception($ex); 103 private function _startElement($file, $name, $attrib) 105 switch(strtolower($name)) { 107 $this->_source = null; 108 $this->_stag = false; 109 $this->_ttag = false; 110 $this->_scontent = null; 111 $this->_tcontent = null; 124 private function _endElement($file, $name) 126 switch (strtolower($name)) { 128 $this->_stag = false; 132 if (!empty($this->_scontent) and !empty($this->_tcontent) or 133 (isset($this->_data[$this->_target][$this->_scontent]) === false)) { 134 $this->_data[$this->_target][$this->_scontent] = $this->_tcontent; 136 $this->_ttag = false; 144 private function _contentElement($file, $data) 146 if ($this->_stag === true) { 147 $this->_scontent .= $data; 150 if ($this->_ttag === true) { 151 $this->_tcontent .= $data; 155 private function _findEncoding($filename) 157 $file = file_get_contents($filename, null, null, 0, 100); 158 if (strpos($file, "encoding") !== false) { 159 $encoding = substr($file, strpos($file, "encoding") + 9); 160 $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); 171 public function toString()
_loadTranslationData($filename, $locale, array $options=array())