00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00030 class TranslationExportXaraya implements ITranslationExport
00031 {
00032
00033 private $RootTimeStamp;
00034 private $SilentMode;
00045 private function &ExportProject(TranslationProject $project)
00046 {
00047 $langXml = new DOMDocument();
00048
00049 $langXml->LoadXML($project->GetSkeleton());
00050
00051
00052 $strings = new StringIterator($project->GetID());
00053 foreach($strings as $str)
00054 {
00055 $projStrings["###".$str->GetStringID()."###"] = $this->FixEntity($str->GetOriginal());
00056
00057 $projStrings["###".$str->GetStringID()."t###"] = $this->FixEntity($str->GetTranslation());
00058
00059
00060
00061
00062
00063 }
00064
00065
00066 $xpath = new DOMXPath($langXml);
00067 $xpath->registerNamespace("m","http://xaraya.com/2002/ns/translations");
00068 $entryNodes = $xpath->query("//m:translations/m:entry");
00069
00070
00071 foreach ($entryNodes as $entry)
00072 {
00073 $origNodes = $xpath->query("m:string", $entry);
00074 $transNodes = $xpath->query("m:translation", $entry);
00075
00076 if($origNodes->item(0)->nodeValue == "")
00077 {
00078 echo "Empty Original node in the file:".$project->GetName().".\n";
00079 }
00080 else
00081 {
00082
00083 $origNodes->item(0)->nodeValue = $projStrings[$origNodes->item(0)->nodeValue];
00084
00085 $transNodes->item(0)->nodeValue = $projStrings[$transNodes->item(0)->nodeValue];
00086
00087 }
00088 }
00089 $xmlContent =& $langXml->saveXML();
00090 return $xmlContent;
00091 }
00092
00101 function FixEntity($text)
00102 {
00103 $s = str_replace("&", "&", $text);
00104 $s = str_replace("\"", """, $s);
00105 $s = str_replace("<", "<", $s);
00106 $s = str_replace(">", ">", $s);
00107 return $s;
00108 }
00109
00119 private function ProcessRecursive($dir, ProjectIterator $projectIterator)
00120 {
00121
00122 foreach($projectIterator as $project)
00123 {
00124
00125 if($this->RootTimeStamp <= $project->GetLastSeen())
00126 {
00127
00128 if($project->GetDocument() == "")
00129 {
00130
00131
00132 $newDir = $dir."/".$project->GetName();
00133 if(!is_dir($newDir))
00134 {
00135 $ret = mkdir($newDir);
00136 if(!$ret)
00137 {
00138 throw new Exception("Failed to create directory $newDir, no permission or disk full.");
00139 }
00140 }
00141 if($projectIterator->hasChildren())
00142 {
00143 $this->ProcessRecursive($newDir, $projectIterator->getChildren());
00144 }
00145 }
00146 else
00147 {
00148
00149
00150 $export = $this->ExportProject($project);
00151 $bytes = file_put_contents($dir."/".$project->GetName(), $export);
00152 if($bytes != strlen($export))
00153 {
00154 throw new Exception("Failed to save ".$dir."/".$project->GetName().", no permission or disk full.");
00155 }
00156 if(!$this->SilentMode)
00157 {
00158 echo("Saved: ".$dir."/".$project->GetName()."\n");
00159 }
00160 }
00161 }
00162 }
00163
00164 }
00165
00175 public function Export($localeName, $silentMode = false)
00176 {
00177 $this->SilentMode = $silentMode;
00178
00179 $localeID = TranslationProject::$LocaleIDCache[$localeName];
00180 if(empty($localeID))
00181 {
00182 throw new Exception("ExportXaraya called with unknown locale name: $localeName");
00183 }
00184
00185
00186 if(!is_dir(GetConfigVar('export_path')))
00187 {
00188 throw new Exception("Export path points to non-existing directory: ".GetConfigVar('export_path'));
00189 }
00190 $dir = GetConfigVar('export_path')."/".$localeName;
00191 if(!is_dir($dir))
00192 {
00193 $ret = mkdir($dir, 0755);
00194 if(!$ret)
00195 {
00196 throw new Exception("Failed to create directory $dir, no permission or disk full.");
00197 }
00198 }
00199 $dir = GetConfigVar('export_path')."/".$localeName."/xml/";
00200 if(!is_dir($dir))
00201 {
00202 $ret = mkdir($dir, 0755);
00203 if(!$ret)
00204 {
00205 throw new Exception("Failed to create directory $dir, no permission or disk full.");
00206 }
00207 }
00208
00209
00210 $rootProject = new TranslationProject();
00211 $rootProject->LoadRoot("Xaraya", $localeID);
00212 $this->RootTimeStamp = $rootProject->GetLastSeen();
00213
00214 $allProjects = new ProjectIterator($rootProject->GetID(), $localeID);
00215
00216 $this->ProcessRecursive($dir, $allProjects);
00217 }
00218 }
00219 ?>