Search Results for

    Show / Hide Table of Contents

    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
      ConvertPackage Transforms a third-party package format into a format Trados Studio recognizes.
      ConvertReturnPackage Converts a Trados Studio return package into the third-party package format.
    • Decorate the class with the ExternalPackageConvertorExtension attribute:

      Property Description
      Id Unique identifier for the converter. We recommend using a combination of the project namespace and class name to avoid conflicts.
      Name Display name for the converter
      Description Description of the converter
      PackageFileFilter File filter for the Windows file dialog (e.g., "Sample Packages (.zip)|.zip"). This lets users see only compatible files.
      PackageFileExtension File extension of the package to import (e.g., ".zip")
      ReturnPackageFileExtension File 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
      projectName The name of the final project to import.
      sourceLanguage The source language of the project to import.
      createdAt The DateTime creation details.
      createdBy The user who created the package.
      originalProjectGuid Pass Guid.Empty if 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");
    }
    
    • Improve this Doc
    In this article
    Back to top Generated by DocFX