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 $_useId =
true;
45 private $_srclang =
null;
49 private $_content =
null;
50 private $_data = array();
64 $this->_data = array();
66 #require_once 'Zend/Translate/Exception.php'; 70 if (isset($options['useId
'])) { 71 $this->_useId = (boolean) $options['useId
']; 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); 110 protected function _startElement($file, $name, $attrib) 112 if ($this->_seg !== null) { 113 $this->_content .= "<".$name; 114 foreach($attrib as $key => $value) { 115 $this->_content .= " $key=\"$value\""; 117 $this->_content .= ">"; 119 switch(strtolower($name)) { 121 if (empty($this->_useId) && isset($attrib['srclang
'])) { 122 if (Zend_Locale::isLocale($attrib['srclang
'])) { 123 $this->_srclang = Zend_Locale::findLocale($attrib['srclang
']); 125 if (!$this->_options['disableNotices
']) { 126 if ($this->_options['log
']) { 127 $this->_options['log
']->notice("The language '{$attrib[
'srclang']}
' can not be set because it does not exist."); 129 trigger_error("The language '{$attrib[
'srclang']}
' can not be set because it does not exist.", E_USER_NOTICE); 133 $this->_srclang = $attrib['srclang
']; 138 if (isset($attrib['tuid
'])) { 139 $this->_tu = $attrib['tuid
']; 143 if (isset($attrib['xml:lang
'])) { 144 if (Zend_Locale::isLocale($attrib['xml:lang
'])) { 145 $this->_tuv = Zend_Locale::findLocale($attrib['xml:lang
']); 147 if (!$this->_options['disableNotices
']) { 148 if ($this->_options['log
']) { 149 $this->_options['log
']->notice("The language '{$attrib[
'xml:lang']}
' can not be set because it does not exist."); 151 trigger_error("The language '{$attrib[
'xml:lang']}
' can not be set because it does not exist.", E_USER_NOTICE); 155 $this->_tuv = $attrib['xml:lang
']; 158 if (!isset($this->_data[$this->_tuv])) { 159 $this->_data[$this->_tuv] = array(); 165 $this->_content = null; 180 protected function _endElement($file, $name) 182 if (($this->_seg !== null) and ($name !== 'seg
')) { 183 $this->_content .= "</".$name.">"; 185 switch (strtolower($name)) { 194 if (!empty($this->_srclang) && ($this->_srclang == $this->_tuv)) { 195 $this->_tu = $this->_content; 198 if (!empty($this->_content) or (!isset($this->_data[$this->_tuv][$this->_tu]))) { 199 $this->_data[$this->_tuv][$this->_tu] = $this->_content; 214 protected function _contentElement($file, $data) 216 if (($this->_seg !== null) and ($this->_tu !== null) and ($this->_tuv !== null)) { 217 $this->_content .= $data; 228 protected function _findEncoding($filename) 230 $file = file_get_contents($filename, null, null, 0, 100); 231 if (strpos($file, "encoding") !== false) { 232 $encoding = substr($file, strpos($file, "encoding") + 9); 233 $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); 244 public function toString() _loadTranslationData($filename, $locale, array $options=array())