/**
  * exports all projects to a zip file - currently not working
  */
 public static function exportProjects()
 {
     $zip = new ZipArchive();
     $filename = $path = APPPATH . "resources/languageforge/semdomtrans/GoogleTranslateHarvester/exportedProjects.zip";
     if ($zip->open($filename, ZipArchive::CREATE) !== TRUE) {
         exit("cannot open <{$filename}>\n");
     } else {
         $projects = SemDomTransProjectCommands::getOpenSemdomProjects($userId);
         foreach ($projects->entries as $p) {
             $e = new SemDomXMLExporter($p, false, $p->isSourceLanguage && $p->languageIsoCode != 'en', !$p->isSourceLanguage);
             $e->run();
             $zip->addFile($p->{$xmlFilePath}, basename($p->{$xmlFilePath}));
         }
         $zip->close();
     }
 }
 public function testSemDomImportExport_ImportExportPreserveXMLFile()
 {
     $environ = new SemDomMongoTestEnvironment();
     $environ->clean();
     $englishProject = $environ->getEnglishProjectAndCreateIfNecessary();
     $exporter = new SemDomXMLExporter($englishProject, false, true, false);
     $exporter->run();
     $sourcePath = $englishProject->xmlFilePath;
     $destinationPath = $englishProject->getAssetsFolderPath() . DIRECTORY_SEPARATOR . $englishProject->projectCode . 'Export.xml';
     $sourceStr = trim(file_get_contents($sourcePath), "\n");
     $sourceArr = explode("\n", $sourceStr);
     $destStr = trim(file_get_contents($destinationPath), "\n");
     $destArr = explode("\n", $destStr);
     for ($i = 0; $i < count($destArr); $i++) {
         if ($i % 500 == 0) {
             $this->assertEquals($sourceArr[$i], $destArr[$i]);
             //$this->assertEqual(substr($sourceArr[$i], 0, -1), $destArr[$i]);
         }
     }
     $environ->clean();
 }
예제 #3
0
<?php

require_once '../scriptsConfig.php';
use Api\Library\Languageforge\Semdomtrans;
use Api\Library\Languageforge\Semdomtrans\SemDomXMLExporter;
use Api\Model\Languageforge\SemDomTransProjectModel;
$lang = $argv[1];
$version = SemDomTransProjectModel::SEMDOM_VERSION;
$testMode = false;
$projectModel = new SemDomTransProjectModel();
$projectModel->readByProperties(array("languageIsoCode" => $lang, "semdomVersion" => $version));
$xml = simplexml_load_file($projectModel->xmlFilePath);
$exporter = new SemDomXMLExporter($projectModel, $testMode, $argv[2] == "1", $argv[3] == "1");
$exporter->run();
 private function _processDomainNode($domainNode)
 {
     if ($this->_xml) {
         $guid = (string) $domainNode['guid'];
     }
     $s = new SemDomTransItemModel($this->_projectModel);
     $s->readByProperty("xmlGuid", $guid);
     $abbreviation = $this->_getPathVal($domainNode->xpath("Abbreviation/AUni[@ws='en']"));
     // if XML file does not have to be recreated, just assign to appropriate fields
     // if XML has to be recreated, then add appropriate children nodes to XML file
     if (!$this->_recreateXMLFile) {
         $name = $domainNode->xpath("Name/AUni[@ws='{$this->_lang}']")[0];
         $description = $domainNode->xpath("Description/AStr[@ws='{$this->_lang}']")[0]->xpath("Run[@ws='{$this->_lang}']")[0];
         $name[0] = SemDomTransStatus::isApproved($s->name->status) ? $s->name->translation : '';
         $description[0] = SemDomTransStatus::isApproved($s->description->status) ? $s->description->translation : '';
     } else {
         $name = $domainNode->Name;
         $nameChild = clone $domainNode->Name->AUni;
         $nameChild["ws"] = $this->_lang;
         $nameChild[0] = SemDomTransStatus::isApproved($s->name->status) ? $s->name->translation : '';
         SemDomXMLExporter::_addChild($name, $nameChild);
         $description = $domainNode->Description;
         $descriptionChild = clone $domainNode->Description->AStr;
         $descriptionChild["ws"] = $this->_lang;
         $descriptionChild->Run["ws"] = $this->_lang;
         $descriptionChild->Run[0] = SemDomTransStatus::isApproved($s->description->status) ? $s->description->translation : '';
         SemDomXMLExporter::_addChild($description, $descriptionChild);
     }
     $questions = new ArrayOf(function ($data) {
         return new SemDomTransQuestion();
     });
     $searchKeys = new ArrayOf(function ($data) {
         return new SemDomTransTranslatedForm();
     });
     if (property_exists($domainNode, 'Questions')) {
         $questionsXML = $domainNode->Questions;
         // parse nested questions
         $index = 0;
         foreach ($questionsXML->children() as $questionXML) {
             // if XML file does not have to be recreated, just assign to appropriate fields
             // if XML has to be recreated, then add appropriate children nodes to XML file
             if (!$this->_recreateXMLFile) {
                 $question = $this->_getNodeOrNull($questionXML->xpath("Question/AUni[@ws='{$this->_lang}']"));
                 $terms = $this->_getNodeOrNull($questionXML->xpath("ExampleWords/AUni[@ws='{$this->_lang}']"));
                 if ($question != null && SemDomTransStatus::isApproved($s->questions[$index]->question->status)) {
                     $question[0] = $s->questions[$index]->question->translation;
                 } else {
                     $question[0] = '';
                 }
                 if ($terms != null && SemDomTransStatus::isApproved($s->questions[$index]->question->status)) {
                     $terms[0] = $s->questions[$index]->terms->translation;
                 }
             } else {
                 $question = $questionXML->Question;
                 $terms = $questionXML->ExampleWords;
                 if (!empty($question)) {
                     $questionChild = clone $question->AUni;
                     $questionChild["ws"] = $this->_lang;
                     if (SemDomTransStatus::isApproved($s->questions[$index]->question->status)) {
                         $questionChild[0] = $s->questions[$index]->question->translation;
                     } else {
                         $questionsChild[0] = '';
                     }
                     SemDomXMLExporter::_addChild($question, $questionChild);
                 }
                 if (!empty($terms)) {
                     $termsChild = clone $terms->AUni;
                     $termsChild["ws"] = $this->_lang;
                     if (SemDomTransStatus::isApproved($s->questions[$index]->terms->status)) {
                         $termsChild[0] = $s->questions[$index]->question->translation;
                     } else {
                         $termsChild[0] = '';
                     }
                     $termsChild[0] = $s->questions[$index]->terms->translation;
                     SemDomXMLExporter::_addChild($terms, $termsChild);
                 }
             }
             $index++;
         }
     }
     //print "Processed $abbreviation \n";
     // recurse on sub-domains
     if (property_exists($domainNode, 'SubPossibilities')) {
         foreach ($domainNode->SubPossibilities->children() as $subDomainNode) {
             $this->_processDomainNode($subDomainNode);
         }
     }
 }