Xartm could be used to translate any software, documents or website content. All you need is to create import filters implementing "ITranslationImport" and "ITranslationExport" interfaces.
Import will result in two data types: projects, strings. Project is usually a directory or a file, while the strings are the smallest units to be translated, which are displayed as single text edits on the GUI.
See generated API phpDoc for function parameters.
Following the code seen in TranslationImportXaraya, it's very easy to implement a filter, all you need is to identify required projects (for example folders, files) loop through them, try loading the project to see if it exists, if not create a new one.
function ProcessDir(RecursiveDirectoryIterator $dirIterator, TranslationProject $parentProject) { foreach($dirIterator as $file) { // Find or create this project (dir/file) $newProject = new TranslationProject(); if(!$newProject->Load($parentProject->GetID(), $file->getFilename(), $parentProject->GetLocaleID(), false)) { $newProject->CreateProject($parentProject->GetRootID(), $parentProject->GetID(), $file->getFilename(), $file->isDir(), $parentProject->GetLocaleID()); } $newProject->Save(); // Import strings (xml in Xaraya) if($file->isFile() && preg_match("/\.xml$/", $file->getFilename())) { $this->ImportFile($file->getPathname(), $newProject); } // Recurese into subfolders if($file->isDir()) { $this->ProcessDir($dirIterator->getChildren(), $newProject); } } }
If the given project project contains strings to translate, you must import the necessary strings and assign them to the given project. You must also be able to insert their current translation if any.
private function ImportFile($fullName, TranslationProject $thisProject) { // Identify strings in this file. [...] // Store strings foreach ($entryNodes as $entry) { $str = new TranslationString( 0, $projID, $origNodes->item(0)->nodeValue, $locID, $transNodes->item(0)->nodeValue, 0); $str->SetRowOrder($rowCount++); $id = $str->Save(); // Use the returned ID in skeleton [...] } // Save the project again $thisProject->SetDocument($document); $thisProject->SetSkeleton($skeleton); $thisProject->Save(); }
Skeleton and Document in the TranslationProject can contain whatever you need to be able to export the finished translation of the string. The $id is returned by TranslationString->Save() should be used to create a placeholder for the translated string in the skeleton.
In Xaraya file import/export XarTM uses ###34### as placeholder for original English strings and ###34t### for placeholder of the translation.
An example skeleton and document may look like this.
Exporting can use ProjectIterator, which can recurisvely loop on all projects, and you can restore the translated content's original format, for example create files.
Exporting translated strings in XarTM is done by replacing the ###34### like strings in the stored project Skeleton by the strings refered by the integer ID.