00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 include_once("lib/TranslationProject.php");
00022
00043 class TranslationImportXaraya implements TranslationImport
00044 {
00045 private $LocaleID;
00046
00051 function __construct()
00052 {
00053 }
00054
00062 private function ImportFile($fullName, TranslationProject $thisProject)
00063 {
00064
00065 $langXml = new DOMDocument();
00066 if(!$langXml->load($fullName))
00067 {
00068 throw new Exception("Can't load language XML file.\n");
00069 }
00070
00071
00072 $document = $langXml->saveXML();
00073 $thisProject->SetDocument($document);
00074
00075
00076 $xpath = new DOMXPath($langXml);
00077 $xpath->registerNamespace("m","http://xaraya.com/2002/ns/translations");
00078 $entryNodes = $xpath->query("//m:translations/m:entry");
00079
00080 $projID = $thisProject->GetID();
00081 $locID = $thisProject->GetLocaleID();
00082
00083 $rowCount = 0;
00084
00085
00086 foreach ($entryNodes as $entry)
00087 {
00088 $origNodes = $xpath->query("m:string", $entry);
00089 $transNodes = $xpath->query("m:translation", $entry);
00090
00091 if($origNodes->item(0)->nodeValue == "")
00092 {
00093 echo "Empty Original node in the current file.\n";
00094 }
00095 else
00096 {
00097
00098 $str = new TranslationString(
00099 0,
00100 $projID,
00101 $origNodes->item(0)->nodeValue,
00102 $locID,
00103 $transNodes->item(0)->nodeValue,
00104 0);
00105 $str->SetRowOrder($rowCount++);
00106 $id = $str->Save();
00107
00108 $origNodes->item(0)->nodeValue = "###${id}###";
00109 $transNodes->item(0)->nodeValue = "###${id}t###";
00110
00111 }
00112 }
00113
00114
00115 $skeleton = $langXml->saveXML();
00116 $thisProject->SetSkeleton($skeleton);
00117 $thisProject->Save();
00118 }
00119
00131 function ProcessDir(RecursiveDirectoryIterator $dirIterator, TranslationProject $parentProject)
00132 {
00133 foreach($dirIterator as $file) {
00134
00135
00136 $newProject = new TranslationProject();
00137 $fname = preg_replace('/.*\
00138
00139 if(!$newProject->Load($parentProject->GetID(), $fname, $parentProject->GetLocaleID()))
00140 {
00141 $newProject->CreateProject($parentProject->GetID(), $fname, $parentProject->GetLocaleID());
00142 }
00143
00144 $newProject->Save();
00145
00146
00147 if($file->isFile() && preg_match("/\.xml$/", $fname))
00148 {
00149 echo "process_file(".$file->getPathname().")\n";
00150 $this->ImportFile($file->getPathname(), $newProject);
00151 }
00152
00153
00154 if($file->isDir()) {
00155 $this->ProcessDir($dirIterator->getChildren(), $newProject);
00156 }
00157 }
00158 }
00159
00167 function Import($localeName)
00168 {
00169 $localeID = TranslationProject::$LocaleIDCache[$localeName];
00170 if(empty($localeID))
00171 {
00172 throw new Exception("ExportXaraya called with unknown locale name: $localeName");
00173 }
00174
00175 $dir = GetConfigVar('import_path')."/".$localeName."/xml/";
00176 if(!is_dir($dir))
00177 {
00178 throw new Exception("ExportXaraya using nonexisting directory: $dir");
00179 }
00180
00181 $this->LocaleID = $localeID;
00182
00183
00184 $rootProject = new TranslationProject();
00185
00186
00187 if(!$rootProject->LoadRoot("Xaraya", $this->LocaleID))
00188 {
00189
00190 $rootProject->CreateRootProject("Xaraya", $this->LocaleID);
00191 }
00192
00193
00194 if(!$rootProject->Save())
00195 {
00196 throw new Exception("Cannot create root project for Xaraya.");
00197 }
00198
00199
00200 $dirIterator = new RecursiveDirectoryIterator($dir);
00201 $this->ProcessDir($dirIterator, $rootProject);
00202 }
00203 }
00204
00205 ?>