66 $langXml =
new DOMDocument();
72 foreach($strings as $str)
74 $projStrings[
"###".$str->GetStringID().
"###"] = $this->
FixEntity($str->GetOriginal());
76 $projStrings[
"###".$str->GetStringID().
"t###"] = $this->
FixEntity($str->GetTranslation());
85 $xpath =
new DOMXPath($langXml);
86 $xpath->registerNamespace(
"m",$this->XmlNameSpace);
87 $entryNodes = $xpath->query(
"//m:translations/m:entry");
90 foreach ($entryNodes as $entry)
92 $origNodes = $xpath->query(
"m:string", $entry);
93 $transNodes = $xpath->query(
"m:translation", $entry);
95 if($origNodes->item(0)->nodeValue ==
"")
97 echo
"Empty Original node in the file:".$project->GetName().
".\n";
102 $origNodes->item(0)->nodeValue = $projStrings[$origNodes->item(0)->nodeValue];
104 $transNodes->item(0)->nodeValue = $projStrings[$transNodes->item(0)->nodeValue];
108 $xmlContent = $langXml->saveXML();
122 $s = str_replace(
"&",
"&", $text);
123 $s = str_replace(
"\"",
""", $s);
124 $s = str_replace(
"<",
"<", $s);
125 $s = str_replace(
">",
">", $s);
141 foreach($projectIterator as $project)
144 if($this->RootTimeStamp <= $project->GetLastSeen())
147 if($project->GetIsFolder())
151 $newDir = $dir.
"/".$project->GetName();
154 $ret = mkdir($newDir);
157 throw new Exception(
"Failed to create directory $newDir, no permission or disk full.");
170 if(preg_match(
"/\.xml$/", $project->GetName()))
177 $export = $project->GetDocument();
180 $bytes = file_put_contents($dir.
"/".$project->GetName(), $export);
181 if($bytes != strlen($export))
183 throw new Exception(
"Failed to save ".$dir.
"/".$project->GetName().
", no permission or disk full.");
185 if(!$this->SilentMode)
187 echo(
"Saved: ".$dir.
"/".$project->GetName().
"\n");
191 if($this->XarayaRoot !=
"")
212 if(!preg_match(
"/\.xml$/", $project->
GetName()))
220 $pid = $project->
GetID();
228 $pid = $proj->GetParentID();
232 if(count($parents) < 4)
240 for($i = 0; $i < count($parents); $i++)
242 $path[] = $parents[count($parents) - $i - 1]->GetName();
247 $xmlPath .=
"/".$path[count($path)-1];
252 if(count($path) == 4 &&
253 ($path[count($path)-1] ==
"common.xml" || $path[count($path)-1] ==
"fuzzy.xml"))
258 $mainFolder = $path[1];
259 $entityName = $path[2];
268 $codeFile =
"modules/".$entityName.
"/xar".$path[3];
272 if($path[3] ==
"templates")
278 for($i = 4; $i < count($path); $i++)
280 $codeFile .=
"/".$path[$i];
284 $codeFile = preg_replace(
"/\.xml$/", $fileExt, $codeFile);
289 $codeFile =
"themes/".$entityName;
292 for($i = 3; $i < count($path); $i++)
294 $codeFile .=
"/".$path[$i];
298 $codeFile = preg_replace(
"/\.xml$/",
".xt", $codeFile);
303 if(!file_exists($this->XarayaRoot.
"/".$codeFile))
305 $this->
LogError(
"No corresponding code file: $xmlPath [$codeFile]\n");
315 $handle = fopen($this->ErrorLogFile,
"a+");
316 fwrite($handle, $msg);
328 public function Export($localeName, $silentMode =
false)
330 $this->SilentMode = $silentMode;
335 throw new Exception(
"Export called with unknown locale name: $localeName");
341 throw new Exception(
"Export path points to non-existing directory: ".
GetConfigVar(
'export_path'));
346 $ret = mkdir($dir, 0755);
349 throw new Exception(
"Failed to create directory $dir, no permission or disk full.");
352 $dir =
GetConfigVar(
'export_path').
"/".$localeName.
"/xml/";
355 $ret = mkdir($dir, 0755);
358 throw new Exception(
"Failed to create directory $dir, no permission or disk full.");
363 $this->ErrorLogFile =
GetConfigVar(
'export_path').
"/".$localeName.
"/xartm_errors.txt";
364 if(file_exists($this->ErrorLogFile))
367 unlink($this->ErrorLogFile);
369 echo(
"Errors will be written to:".$this->ErrorLogFile.
"\n");
372 $this->XarayaRoot =
GetConfigVar(
'export_path').
"/../..";
373 if(!file_exists($this->XarayaRoot.
"/index.php"))
375 echo(
"No ".$this->ProjectName.
" root found:".$this->XarayaRoot.
"/index.php. Won't detect obsolete files into errorlog.\n");
376 $this->XarayaRoot =
"";
381 $rootProject->LoadRoot($this->ProjectName, $localeID);
382 $this->RootTimeStamp = $rootProject->GetLastSeen();
387 $allProjects =
new ProjectIterator($rootProject->GetID(), $localeID,
false);
ProcessRecursive($dir, ProjectIterator $projectIterator)
CheckCodeFiles(TranslationProject $project)
& ExportProject(TranslationProject $project)
static ClearCache($localeID)
Export($localeName, $silentMode=false)