/** * Short description of method read * * @access public * @author firstname and lastname of author, <*****@*****.**> * @throws tao_helpers_translation_TranslationException * @return mixed */ public function read() { $file = $this->getFilePath(); if (!file_exists($file)) { throw new tao_helpers_translation_TranslationException("The translation file '{$file}' does not exist."); } // Create the translation file. $tf = new tao_helpers_translation_POFile(); $fc = implode('', file($file)); $matched = preg_match_all('/((?:#[\\.:,\\|]{0,1}\\s+(?:.*?)\\n)*)' . '(msgctxt\\s+(?:"(?:[^"]|\\\\")*?"\\s*)+)?' . '(msgid\\s+(?:"(?:[^"]|\\\\")*?"\\s*)+)\\s+' . '(msgstr\\s+(?:"(?:[^"]|\\\\")*?(?<!\\\\)"\\s*)+)/', $fc, $matches); preg_match('/sourceLanguage: (.*?)\\n/s', $fc, $sourceLanguage); preg_match('/targetLanguage: (.*?)\\n/s', $fc, $targetLanguage); if (count($sourceLanguage)) { $tf->setSourceLanguage(substr($sourceLanguage[1], 0, 5)); } if (count($targetLanguage)) { $tf->setTargetLanguage(substr($targetLanguage[1], 0, 5)); } if ($matched) { for ($i = 0; $i < $matched; $i++) { $annotations = $matches[1][$i]; $msgctxt = preg_replace('/\\s*msgctxt\\s*"(.*)"\\s*/s', '\\1', $matches[2][$i]); $msgid = preg_replace('/\\s*msgid\\s*"(.*)"\\s*/s', '\\1', $matches[3][$i]); $msgstr = preg_replace('/\\s*msgstr\\s*"(.*)"\\s*/s', '\\1', $matches[4][$i]); // Do not include meta data as a translation unit.. if ($msgid !== '') { // Sanitze the strings. $msgid = tao_helpers_translation_POUtils::sanitize($msgid); $msgstr = tao_helpers_translation_POUtils::sanitize($msgstr); $msgctxt = tao_helpers_translation_POUtils::sanitize($msgctxt); $tu = new tao_helpers_translation_POTranslationUnit(); // Set up source & target. $tu->setSource($msgid); if ($msgstr !== '') { $tu->setTarget($msgstr); } if ($msgctxt) { $tu->setContext($msgctxt); } // Deal with annotations $annotations = tao_helpers_translation_POUtils::unserializeAnnotations($annotations); foreach ($annotations as $name => $value) { $tu->addAnnotation($name, $value); } $tf->addTranslationUnit($tu); } } } $this->setTranslationFile($tf); }
/** * @param $child * @param $xmlNS * @param $about * @param $tus * @return array */ protected function processUnit($child, $xmlNS, $about, $tus) { if ($child->hasAttributeNS($xmlNS, 'lang')) { $sourceLanguage = 'en-US'; $targetLanguage = $child->getAttributeNodeNS($xmlNS, 'lang')->value; $source = $child->nodeValue; $target = ''; //$child->nodeValue; $tu = new tao_helpers_translation_POTranslationUnit(); $tu->setSource($source); $tu->setTarget($target); $tu->setSourceLanguage($sourceLanguage); $tu->setTargetLanguage($targetLanguage); $tu->setAnnotations(array($about)); $tu->setContext($child->namespaceURI . $child->localName); $tus[] = $tu; return $tus; } return $tus; }