Processing custom project package formats
The Trados Studio Integration API enables you to transform third-party packages into a format that Trados Studio can work with. This page describes the steps required to create a custom package converter.
Declare a custom package converter
Creating a custom package converter starts with the declaration:
Implement the IExternalPackageConverter interface with the following methods:
Method Name Description ConvertPackageTransforms a third-party package format into a format Trados Studio recognizes. ConvertReturnPackageConverts a Trados Studio return package into the third-party package format. Decorate the class with the ExternalPackageConvertorExtension attribute:
Property Description IdUnique identifier for the converter. We recommend using a combination of the project namespace and class name to avoid conflicts. NameDisplay name for the converter DescriptionDescription of the converter PackageFileFilterFile filter for the Windows file dialog (e.g., "Sample Packages (.zip)|.zip"). This lets users see only compatible files. PackageFileExtensionFile extension of the package to import (e.g., ".zip") ReturnPackageFileExtensionFile extension of the return package (e.g., ".zip")
The following code sample shows the basic structure:
[ExternalPackageConvertorExtension(
Id = "Sdl.ProjectsOperations.Sample.SamplePackageConverter",
Name = "Sample Package Converter",
Description = "Sample Package Converter",
PackageFileFilter = "Sample Packages (*.zip)|*.zip",
PackageFileExtension = ".zip",
ReturnPackageFileExtension = ".zip")]
public class SamplePackageConverter : IExternalPackageConverter
{
public SamplePackageConverter()
{
}
public PackageConversionResult ConversionResult {get; private set;}
public event EventHandler<PackageConverterMessageEventArgs> PackageMessage;
public event EventHandler<ConvertExternalPackageEventArgs> PackageConverted;
public void ConvertPackage(IConversionContext context, ExternalPackageConversionInfo externalPackageConversionInfo)
{
// your costum logic here
}
public void ConvertReturnPackage(IConversionContext context, ExternalPackageConversionInfo externalPackageConversionInfo)
{
// your custom logic here
}
}
Note
The Open Package and Create Return Package wizards' Data object is available in the custom package converter through the ExternalPackageConversionInfo.CustomData property. This allows third-party developers to use data captured in their custom wizard pages inside the converter.
Import a custom package
Importing a custom package involves implementing the ConvertPackage(IConversionContext context, ExternalPackageConversionInfo externalPackageConversionInfo) method. Typical implementation steps include:
Unzip the package
Create an IPackage object by calling IConversionContext.CreatePackage with these parameters:
Parameter Name Description projectNameThe name of the final project to import. sourceLanguageThe source language of the project to import. createdAtThe DateTimecreation details.createdByThe user who created the package. originalProjectGuidPass Guid.Emptyif this is the first import into Trados Studio. Otherwise, pass the original project ID. Use IConversionContext.CheckForExistingProject() to verify if the project exists in Trados Studio.Add resources to the IPackage object: files, translation memories, termbases, and settings
Package the converted data into Trados Studio format by calling IPackage.Pack() with the target location
Clean up temporary resources and files
public void ConvertPackage(IConversionContext context, ExternalPackageConversionInfo externalPackageConversionInfo)
{
OnPackageConverted(0, "Beginning conversion");
try
{
var projectId = Guid.Empty;
var package = context.CreatePackage("SampleProject",
new Language("en-us"), DateTime.Now, "sample_api", projectId);
AddResourcesToPackage(package);
package.Pack("C:\\SampleLocation\\sample_package.sdlppx");
}
finally
{
Cleanup();
}
OnPackageConverted(100, "Conversion Completed");
}
Export a return package to a custom format
Exporting a return package to a custom format involves implementing the ConvertReturnPackage(IConversionContext context, ExternalPackageConversionInfo externalPackageConversionInfo) method. Typical implementation steps include:
- Open an IPackage object from the return package file by calling IConversionContext.OpenPackage
- Extract the required resources from the IPackage object and create the custom return package
- Clean up temporary resources and files
public void ConvertReturnPackage(IConversionContext context, ExternalPackageConversionInfo externalPackageConversionInfo)
{
OnPackageConverted(0, "Beginning conversion");
try
{
var fromPackage = context.OpenPackage(externalPackageConversionInfo.FromPackagePath);
CreateCustomReturnPackage(fromPackage);
}
finally
{
Cleanup();
}
OnPackageConverted(100, "Conversion Completed");
}