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 $_langset =
null;
46 private $_termentry =
null;
47 private $_content =
null;
48 private $_term =
null;
49 private $_data = array();
63 $this->_data = array();
65 #require_once 'Zend/Translate/Exception.php'; 69 $encoding = $this->_findEncoding($filename); 70 $this->_file = xml_parser_create($encoding); 71 xml_set_object($this->_file, $this); 72 xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); 73 xml_set_element_handler($this->_file, "_startElement", "_endElement"); 74 xml_set_character_data_handler($this->_file, "_contentElement"); 77 Zend_Xml_Security::scanFile($filename); 78 } catch (Zend_Xml_Exception $e) { 79 #require_once 'Zend/Translate/Exception.php
'; 80 throw new Zend_Translate_Exception( 85 if (!xml_parse($this->_file, file_get_contents($filename))) { 86 $ex = sprintf('XML error: %s at line %d of file %s
', 87 xml_error_string(xml_get_error_code($this->_file)), 88 xml_get_current_line_number($this->_file), 90 xml_parser_free($this->_file); 91 #require_once 'Zend/Translate/Exception.php
'; 92 throw new Zend_Translate_Exception($ex); 98 private function _startElement($file, $name, $attrib) 100 if ($this->_term !== null) { 101 $this->_content .= "<".$name; 102 foreach($attrib as $key => $value) { 103 $this->_content .= " $key=\"$value\""; 105 $this->_content .= ">"; 107 switch(strtolower($name)) { 109 $this->_termentry = null; 112 if (isset($attrib['xml:lang
']) === true) { 113 $this->_langset = $attrib['xml:lang
']; 114 if (isset($this->_data[$this->_langset]) === false) { 115 $this->_data[$this->_langset] = array(); 121 $this->_content = null; 129 private function _endElement($file, $name) 131 if (($this->_term !== null) and ($name != "term")) { 132 $this->_content .= "</".$name.">"; 134 switch (strtolower($name)) { 136 $this->_langset = null; 140 if (empty($this->_termentry)) { 141 $this->_termentry = $this->_content; 143 if (!empty($this->_content) or (isset($this->_data[$this->_langset][$this->_termentry]) === false)) { 144 $this->_data[$this->_langset][$this->_termentry] = $this->_content; 153 private function _contentElement($file, $data) 155 if ($this->_term !== null) { 156 $this->_content .= $data; 160 private function _findEncoding($filename) 162 $file = file_get_contents($filename, null, null, 0, 100); 163 if (strpos($file, "encoding") !== false) { 164 $encoding = substr($file, strpos($file, "encoding") + 9); 165 $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); 176 public function toString() _loadTranslationData($filename, $locale, array $options=array())