Sdl Sdk Project Automation Use Template and PreTranslateFiles using Server Based Translation Memories

How is it possible to run AutomaticTask.PreTranslateFiles, using server based Translation Memories?

MainTranslationProviderItem Uri="sdltm.gsdemo.gs.sdlproducts.com/ Global Solution Consultants%2FBC Translation Productivity%2FSDL EMEA LSP%2FSDL LSP Trials%2F{CompanyName}&tmName={TmName}" Enabled="true
private void RunAutomaticTask(FileBasedProject ThisSdlProject, string TargetLanguageCode){
    ProjectFile[] targetFiles = ThisSdlProject.GetTargetLanguageFiles(new Language(CultureInfo.GetCultureInfo(TargetLanguageCode)));
    AutomaticTask preTranslate = ThisSdlProject.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.PreTranslateFiles);
}

I get the error: "The current parameters are not compatible with the Translation Provider Uri Schema"

Parents
  • Hi ,

    Can you please give me more details about what you are trying to achieve and the steps you are doing? 

    What I've tried:

    1. On the active project I have set a server based tm
    2. I get the project programatically and I ran the pre-translate
    3. No error appear using code bellow

    var projectsController = SdlTradosStudio.Application.GetController<ProjectsController>();
    var activeProject = projectsController?.CurrentProject;
    var targetFiles = activeProject.GetTargetLanguageFiles(new Language(new CultureInfo("de-de")));
    var result = activeProject.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.PreTranslateFiles);

    Kind reagrds,

    Andrea Ghisa

Reply
  • Hi ,

    Can you please give me more details about what you are trying to achieve and the steps you are doing? 

    What I've tried:

    1. On the active project I have set a server based tm
    2. I get the project programatically and I ran the pre-translate
    3. No error appear using code bellow

    var projectsController = SdlTradosStudio.Application.GetController<ProjectsController>();
    var activeProject = projectsController?.CurrentProject;
    var targetFiles = activeProject.GetTargetLanguageFiles(new Language(new CultureInfo("de-de")));
    var result = activeProject.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.PreTranslateFiles);

    Kind reagrds,

    Andrea Ghisa

Children
  • This is my code:

    namespace Sdl.Sdk.ProjectGroupShareAssets
    {
        using System;
        using System.Globalization;
        using Sdl.Core.Globalization;
        using Sdl.ProjectAutomation.Core;
        using Sdl.ProjectAutomation.FileBased;
        using System.Xml;
    
        public class ProjectCreator
        {
            public void Create(
                string SourceFiles,
                string SdlProjectPath,
                string SdlTemplateFile
            )
            {
                ProjectTemplateReference SdlTemplateReference = new ProjectTemplateReference(SdlTemplateFile);
    
                XmlDocument XmlTemplateFile = new XmlDocument();
                XmlTemplateFile.Load(SdlTemplateFile);
                XmlNode LanguageDirectionNode = XmlTemplateFile.DocumentElement.SelectSingleNode("/ProjectTemplate/LanguageDirections/LanguageDirection");
                string SourceLanguageCode = LanguageDirectionNode.Attributes["SourceLanguageCode"].InnerText;
                string TargetLanguageCode = LanguageDirectionNode.Attributes["TargetLanguageCode"].InnerText;
    
                FileBasedProject NewSdlProject = new FileBasedProject(this.GetProjectInformation(SourceLanguageCode, TargetLanguageCode, SdlProjectPath), SdlTemplateReference);
    
                this.AddFilesToProject(NewSdlProject, SourceFiles);
                this.ConvertFiles(NewSdlProject);
                this.RunAutomaticTask(NewSdlProject, TargetLanguageCode, "PrepareWithoutProjectTm");
                NewSdlProject.Save();
            }
    
            private ProjectInfo GetProjectInformation(string SourceLanguageCode, string TargetLanguageCode, string SdlProjectPath)
            {
                ProjectInfo info = new ProjectInfo();
                info.Name = "TestProject";
                string[] DateArray = "2020-02-28".Split('-');
                int year = Convert.ToInt32(DateArray[0]);
                int month = Convert.ToInt32(DateArray[1]);
                int day = Convert.ToInt32(DateArray[2]);
                info.DueDate = new DateTime(year, month, day, 12, 0, 0, 0);
                string localProjectFolder = @"" + SdlProjectPath;
                info.LocalProjectFolder = localProjectFolder;
                Language srcLang = new Language(CultureInfo.GetCultureInfo(SourceLanguageCode));
                info.SourceLanguage = srcLang;
                Language[] trgLang = new Language[] { new Language(CultureInfo.GetCultureInfo(TargetLanguageCode)) };
                info.TargetLanguages = trgLang;
                return info;
            }
    
            private void AddFilesToProject(FileBasedProject ThisSdlProject, string folder)
            {
                ThisSdlProject.AddFolderWithFiles(folder, true);
                ProjectFile[] projectFiles = ThisSdlProject.GetSourceLanguageFiles();
                AutomaticTask scan = ThisSdlProject.RunAutomaticTask(
                    projectFiles.GetIds(),
                    AutomaticTaskTemplateIds.Scan
                );
                ProjectFile[] files = ThisSdlProject.GetSourceLanguageFiles();
                for (int i = 0; i < ThisSdlProject.GetSourceLanguageFiles().Length; i++)
                {
                    Guid[] currentFileId = { files[i].Id };
                    string currentFileName = files[i].Name;
                    ThisSdlProject.SetFileRole(currentFileId, FileRole.Translatable);
                }
                AutomaticTask pre_scan = ThisSdlProject.RunAutomaticTask(
                    projectFiles.GetIds(),
                    AutomaticTaskTemplateIds.Scan
                );
            }
    
            private void ConvertFiles(FileBasedProject ThisSdlProject)
            {
                ProjectFile[] files = ThisSdlProject.GetSourceLanguageFiles();
    
                for (int i = 0; i < ThisSdlProject.GetSourceLanguageFiles().Length; i++)
                {
                    if (files[i].Role == FileRole.Translatable)
                    {
                        Guid[] currentFileId = { files[i].Id };
                        AutomaticTask convertTask = ThisSdlProject.RunAutomaticTask(
                            currentFileId,
                            AutomaticTaskTemplateIds.ConvertToTranslatableFormat
                        );
                        AutomaticTask copyTask = ThisSdlProject.RunAutomaticTask(
                            currentFileId,
                            AutomaticTaskTemplateIds.CopyToTargetLanguages
                        );
                    }
                }
            }
    
            private void RunAutomaticTask(FileBasedProject ThisSdlProject, string TargetLanguageCode, string AutomaticTaskOption)
            {
                ProjectFile[] targetFiles = ThisSdlProject.GetTargetLanguageFiles(new Language(CultureInfo.GetCultureInfo(TargetLanguageCode)));
                AutomaticTask preTranslate = ThisSdlProject.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.PreTranslateFiles);
            }
        }
    }

    This is my error (within the sdlproj file):

    <Messages Level="Error" Message="Unexpected exception when configuring file multiFileConverter for task 'Pre-translate Files': Failed to create an instance of translation provider 'sdltm.gsdemo.gs.sdlproducts.com/ Global Solution Consultants%2FBC Translation Productivity%2FSDL EMEA LSP%2FSDL LSP Trials%2F{COMPANY}&amp;tmName=Fruits TM'.." Source="Pre-translate Files">