SDL Project Automation Api -> Project Template using GroupShare Translation Memories

Using SDL Project Automation Api, I'm creating a Project from a Template.

Works fine when using a template that references a File-Based Translation Memory.

However it does not work when using a Server-Based Translation Memory.

Translation Memory is stored in demo version of GroupShare:

gsdemo.gs.sdlproducts.com/.../SDL Global Solution Consultants/BC Translation Productivity/SDL EMEA LSP/SDL LSP Trials/{COMPANY_NAME}

tmName = "FruitsTM"

Error: "The current parameters are not compatible with the Translation Provider Uri Schema"

How can I use Project Templates that contain server-based assets with the Api?

Thanks

Parents Reply Children
  • Thanks, this is based on the original Sdl Project Automation SDK scripts.

    I have stripped out a lot of unnecessary code, as so hopefully this will give you an idea of what I am doing.

    • Creating a project from a template
    • Adding files to the project
    • Converting the files
    • AutomatedTasks -> Prepare
    • AutomatedTasks -> Pre-translating
    • AutomatedTasks -> Analyze 
    • Save the project

    namespace Sdl.SDK.ProjectAutomation.Samples.BatchAnalyze

    {
        using System;
        using System.Collections;
        using System.Globalization;
        using Sdl.Core.Globalization;
        using Sdl.Core.Settings;
        using Sdl.LanguagePlatform.TranslationMemoryApi;
        using Sdl.ProjectAutomation.Core;
        using Sdl.ProjectAutomation.FileBased;
        using Sdl.ProjectAutomation.Settings;
        using System.Xml;
        using System.Linq;
        using Microsoft.Win32;
    
        public class ProjectCreator
        {
            private Guid reportId;
    
            public void Create(
                string ProjectDirectory,
                string ReferenceFiles,
                string SourceLanguageCode,
                string TargetLanguageCode,
                string SdlProjectTemplateFile,
                string ProjectDueDate,
                bool reportCrossFileRepetitions,
                bool reportInternalFuzzyMatchLeverage,
                bool lockContextExact,
                bool reportLocked,
                bool recursion
             )
            {
                # Set the Sdl Template Reference
                	ProjectTemplateReference SdlTemplate = new ProjectTemplateReference(SdlProjectTemplateFile);
                # Create the new Sdl Project
                	FileBasedProject newProject = new FileBasedProject(this.GetProjectInfo(SourceLanguageCode, TargetLanguageCode, ProjectDirectory, ProjectDueDate), SdlTemplate);
                # Add the files
                	this.AddFiles(newProject, ProjectDirectory, recursion, ReferenceFiles);
                # Convert the files
                	this.ConvertFiles(newProject);
                # Get the Settings & Prepare the files
                    this.GetAnalyzeSettings(newProject,TargetLanguageCode,reportCrossFileRepetitions,reportInternalFuzzyMatchLeverage,lockContextExact,reportLocked);
                    this.RunFileAnalysis(newProject, TargetLanguageCode, "Prepare", true);
                # Get the Settings & PreTranslate the files
                    this.GetAnalyzeSettings(newProject,TargetLanguageCode,reportCrossFileRepetitions,reportInternalFuzzyMatchLeverage,lockContextExact,reportLocked);
                    this.RunFileAnalysis(newProject, TargetLanguageCode, "PreTranslate", true);
                # Get the Settings & Analyze the files
                    this.GetAnalyzeSettings(newProject,TargetLanguageCode,reportCrossFileRepetitions,reportInternalFuzzyMatchLeverage,lockContextExact,reportLocked);
                    this.RunFileAnalysis(newProject, TargetLanguageCode, "Analyze", true);
                # Save the Project
                	newProject.Save();
            }
            private ProjectInfo GetProjectInfo(string srcLocale, string trgLocale, string Directory, string ProjectDueDate)
            {
                ProjectInfo info = new ProjectInfo();
                info.Name = srcLocale;
                string[] DateArray = ProjectDueDate.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);
                info.LocalProjectFolder = Directory;
                Language srcLang = new Language(CultureInfo.GetCultureInfo(srcLocale));
                info.SourceLanguage = srcLang;
                Language[] trgLang = new Language[] { new Language(CultureInfo.GetCultureInfo(trgLocale)) };
                info.TargetLanguages = trgLang;
                return info;
            }
            private void AddFiles(FileBasedProject project, string folder, bool recursion, string referenceFiles)
            {
                project.AddFolderWithFiles(folder, recursion);
                ProjectFile[] projectFiles = project.GetSourceLanguageFiles();
                AutomaticTask scan = project.RunAutomaticTask(
                    projectFiles.GetIds(),
                    AutomaticTaskTemplateIds.Scan
                );
                ProjectFile[] files = project.GetSourceLanguageFiles();
                string[] stringArray = referenceFiles.Split(':');
                for (int i = 0; i < project.GetSourceLanguageFiles().Length; i++){
                    Guid[] currentFileId = { files[i].Id };
                    string currentFileName = files[i].Name;
                    project.SetFileRole(currentFileId, FileRole.Translatable);
                    foreach (string x in stringArray){
                        if (x.Contains(currentFileName)){
                            project.SetFileRole(currentFileId, FileRole.Reference);
                        }
                    }
                }
                AutomaticTask pre_scan = project.RunAutomaticTask(
                    projectFiles.GetIds(),
                    AutomaticTaskTemplateIds.Scan
                );
            }
            private void ConvertFiles(FileBasedProject project)
            {
                ProjectFile[] files = project.GetSourceLanguageFiles();
                for (int i = 0; i < project.GetSourceLanguageFiles().Length; i++){
                    if (files[i].Role == FileRole.Translatable){
                        Guid[] currentFileId = { files[i].Id };
                        AutomaticTask convertTask = project.RunAutomaticTask(
                            currentFileId,
                            AutomaticTaskTemplateIds.ConvertToTranslatableFormat
                        );
                        AutomaticTask copyTask = project.RunAutomaticTask(
                            currentFileId,
                            AutomaticTaskTemplateIds.CopyToTargetLanguages
                        );
                    }
                }
            }        
            private void GetAnalyzeSettings(
                FileBasedProject project,
                string trgLocale,
                bool reportCrossFileRepetitions,
                bool reportInternalFuzzyMatchLeverage,
                bool lockContextExact,
                bool reportLocked)
            {
                Language trgLanguage = new Language(CultureInfo.GetCultureInfo(trgLocale));
    
                ISettingsBundle settings = project.GetSettings(trgLanguage);
                AnalysisTaskSettings analyzeSettings = settings.GetSettingsGroup();
    
                analyzeSettings.ReportCrossFileRepetitions.Value = reportCrossFileRepetitions;
                analyzeSettings.ReportInternalFuzzyMatchLeverage.Value = reportInternalFuzzyMatchLeverage;
                if (reportLocked == true){
                    analyzeSettings.GetSetting("ReportLockedSegmentsSeparately").Value = true;
                }
                project.UpdateSettings(trgLanguage, settings);
                if (lockContextExact == true){
                    TranslateTaskSettings pretranslateSettings = settings.GetSettingsGroup();
                    pretranslateSettings.ConfirmAfterApplyingExactMatch.Value = true;
                    pretranslateSettings.LockExactMatchSegments.Value = true;
                    pretranslateSettings.ConfirmAfterApplyingInContextExactMatch.Value = true;
                    pretranslateSettings.LockContextMatchSegments.Value = true;
                }
                project.UpdateSettings(trgLanguage, settings);
            }
    
            private void RunFileAnalysis(FileBasedProject project, string trgLocale, string AutomaticTask, bool populateProjectTm)
            {
                ProjectFile[] targetFiles = project.GetTargetLanguageFiles(new Language(CultureInfo.GetCultureInfo(trgLocale)));
                if (AutomaticTask=="Prepare"){
                    AutomaticTask prepare = project.RunAutomaticTask(
                        targetFiles.GetIds(),
                        AutomaticTaskTemplateIds.PopulateProjectTranslationMemories
                    );
                }
                if (AutomaticTask=="PreTranslate"){
                    AutomaticTask prepareNoTM = project.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.PreTranslateFiles);
                    if(populateProjectTm == true){
    	                AutomaticTask populateProjectMemory = project.RunAutomaticTask(targetFiles.GetIds(), AutomaticTaskTemplateIds.PopulateProjectTranslationMemories);
                    }
                }
                if (AutomaticTask=="Analyze"){
                    AutomaticTask analyzeTask = project.RunAutomaticTask(
                        targetFiles.GetIds(),
                        AutomaticTaskTemplateIds.AnalyzeFiles
                    );
                    this.reportId = analyzeTask.Reports[0].Id;
                }
            }
        }
    }