* @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+(?:"(?:[^"]|\\\\")*?(?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); } }