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 $_lang =
null;
46 private $_content =
null;
48 private $_data = array();
62 $this->_data = array();
63 $this->_lang = $locale;
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 switch(strtolower($name)) { 102 $this->_tag = $attrib['id']; 103 $this->_content = null; 110 private function _endElement($file, $name) 112 switch (strtolower($name)) { 114 if (!empty($this->_tag) and !empty($this->_content) or 115 (isset($this->_data[$this->_lang][$this->_tag]) === false)) { 116 $this->_data[$this->_lang][$this->_tag] = $this->_content; 119 $this->_content = null; 127 private function _contentElement($file, $data) 129 if (($this->_tag !== null)) { 130 $this->_content .= $data; 134 private function _findEncoding($filename) 136 $file = file_get_contents($filename, null, null, 0, 100); 137 if (strpos($file, "encoding") !== false) { 138 $encoding = substr($file, strpos($file, "encoding") + 9); 139 $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1); 150 public function toString() _loadTranslationData($filename, $locale, array $options=array())