_options, $options); if ($options['clear']) { $this->_translate = array(); } if ((in_array('defined_language', $options)) and !empty($options['defined_language'])) { $this->_defined = true; } if (!is_readable($filename)) { throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.'); } $this->_file = xml_parser_create(); xml_set_object($this->_file, $this); xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($this->_file, "_startElement", "_endElement"); xml_set_character_data_handler($this->_file, "_contentElement"); if (!xml_parse($this->_file, file_get_contents($filename))) { throw new Zend_Translate_Exception(sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file))); xml_parser_free($this->_file); } if ($this->_defined !== true) { foreach ($this->_translate as $key => $value) { if (!in_array($key, $this->_languages)) { $this->_languages[$key] = $key; } } } } private function _startElement($file, $name, $attrib) { switch(strtolower($name)) { case 'tu': if (array_key_exists('tuid', $attrib)) { $this->_tu = $attrib['tuid']; } break; case 'tuv': if (array_key_exists('xml:lang', $attrib)) { $this->_tuv = $attrib['xml:lang']; if (!array_key_exists($this->_tuv, $this->_translate)) { $this->_translate[$this->_tuv] = array(); } if (!array_key_exists($this->_tuv, $this->_languages) and ($this->_defined === true)) { $this->_languages[$this->_tuv] = $this->_tuv; } } break; case 'seg': $this->_seg = true; $this->_content = null; break; default: break; } } private function _endElement($file, $name) { switch (strtolower($name)) { case 'tu': $this->_tu = null; break; case 'tuv': $this->_tuv = null; break; case 'seg': $this->_seg = null; if (!empty($this->_content) or !array_key_exists($this->_tu, $this->_translate[$this->_tuv])) { $this->_translate[$this->_tuv][$this->_tu] = $this->_content; } break; default: break; } } private function _contentElement($file, $data) { if (($this->_seg !== null) and ($this->_tu !== null) and ($this->_tuv !== null)) { $this->_content .= $data; } } /** * Returns the adapter name * * @return string */ public function toString() { return "Tmx"; } }