XarTM - Xaraya Translation Memory

Table of contents

Programming import/export filters

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.

Import filter

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.

Processing projects

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()))
			$newProject->CreateProject($parentProject->GetID(), $file->getFilename(), $file->isDir(), $parentProject->GetLocaleID());
		// Import strings (xml in Xaraya)
		if($file->isFile() && preg_match("/\.xml$/", $file->getFilename()))
			$this->ImportFile($file->getPathname(), $newProject);
		// Recurese into subfolders
			$this->ProcessDir($dirIterator->getChildren(), $newProject);

Processing strings

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(
		$id = $str->Save();
		// Use the returned ID in skeleton
	// Save the project again

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.

XarTM database example screenshot

Export filter

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.