示例#1
0
文件: job.php 项目: andresmaeso/neno
 /**
  * Process a file
  *
  * @return bool True on success, false otherwise
  */
 public function processJobFinished()
 {
     $config = JFactory::getConfig();
     $tmpPath = $config->get('tmp_path');
     $filename = $this->getFileName();
     $fileContents = json_decode(file_get_contents($tmpPath . '/' . $filename . '.json' . '/' . $filename . '.json'), true);
     if ($fileContents !== null) {
         foreach ($fileContents['strings'] as $translationId => $translationText) {
             /* @var $translation NenoContentElementTranslation */
             $translation = NenoContentElementTranslation::load($translationId, false, true);
             if (!empty($translation)) {
                 $translation->setString(NenoHelper::replaceTranslationsInHtmlTag($translation->getOriginalText(), html_entity_decode($translationText, ENT_COMPAT | ENT_HTML401, $this->getCorrectEncodingCharset($this->getToLanguage()))));
                 // Mark this translation method as completed
                 $translation->markTranslationMethodAsCompleted($this->translationMethod->id);
                 if ($translation->isBeingCompleted()) {
                     $translation->setState(NenoContentElementTranslation::TRANSLATED_STATE);
                 }
                 // Saving translation
                 if ($translation->persist()) {
                     // Move translation to the target even if it's not completed. Machine => Professional || Professional => Manual
                     $translation->moveTranslationToTarget();
                 }
             }
         }
         // Ensure the shadow tables of the target language have their language column (if there's any) properly set.
         $tables = NenoContentElementTable::load(array('translate' => 1));
         /* @var $table NenoContentElementTable */
         foreach ($tables as $table) {
             $table->checkIntegrity($this->getToLanguage());
         }
         return true;
     }
     return false;
 }