Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * @param $f
  * @param $translatableProperties
  * @return tao_helpers_translation_POFile
  * @throws tao_helpers_translation_TranslationException
  */
 protected function extractPoFileFromRDF($f, $translatableProperties)
 {
     $modelExtractor = new tao_helpers_translation_POExtractor(array($f));
     $modelExtractor->setTranslatableProperties($translatableProperties);
     $modelExtractor->extract();
     $translationFile = new tao_helpers_translation_POFile();
     $translationFile->setSourceLanguage(tao_helpers_translation_Utils::getDefaultLanguage());
     $translationFile->setTargetLanguage($this->options['language']);
     $translationFile->addTranslationUnits($modelExtractor->getTranslationUnits());
     $translationFile->setExtensionId($this->options['extension']);
     $this->preparePOFile($translationFile);
     return $translationFile;
 }