/**
  * (non-PHPdoc)
  * @see LTTMParser::parse()
  */
 public function parse($text)
 {
     $tm = new LTTranslationMemory();
     $translationSets = array();
     $text = preg_replace('/\\<!--([^(--\\>)]*)--\\>/', '', $text);
     $lines = explode("\n", $text);
     while (true) {
         $languages = array_shift($lines);
         if (trim($languages) != '') {
             break;
         }
     }
     $languages = array_map('trim', explode(',', $languages));
     foreach ($lines as $line) {
         if (trim($line) == '') {
             continue;
         }
         $values = array_map('trim', explode(',', $line));
         $tu = new LTTMUnit();
         // If there is only one value, interpret it as "should never be translated", and add it for all languages.
         if (count($values) == 1) {
             foreach ($languages as $language) {
                 // Add the translation (or translations) (value, array) of the word in the language (key).
                 $tu->addVariants(array($language => array_map('trim', explode('|', $values[0]))));
             }
         } else {
             foreach ($languages as $nr => $language) {
                 if (array_key_exists($nr, $values)) {
                     // Add the translation (or translations) (value, array) of the word in the language (key).
                     $tu->addVariants(array($language => array_map('trim', explode('|', $values[$nr]))));
                 }
             }
         }
         $tm->addTranslationUnit($tu);
     }
     return $tm;
 }
 /**
  * Sets the end element handler function for the XML parser parser.end_element_handler.
  * 
  * @since 0.4
  * 
  * @param resource $parser The first parameter, parser, is a reference to the XML parser calling the handler.
  * @param string $name The second parameter, name, contains the name of the element for which this handler is called. If case-folding is in effect for this parser, the element name will be in uppercase letters. 
  */
 protected function endElementHandler($parser, $name)
 {
     switch (strtolower($name)) {
         case 'tu':
             // We are leaving the translation unit node, so add the translation unit to the translation memory.
             if ($this->tu->hasVariants()) {
                 $this->tm->addTranslationUnit($this->tu);
             }
             break;
         case 'tuv':
             $this->tu->addVariant($this->currentLanguage, $this->currentTranslation);
             break;
         case 'seg':
             $this->insideSegment = false;
             break;
         case 'ut':
             $this->insideIgnoreNode = false;
             break;
     }
 }