API Pre-Translate Task not working for DeepL MT Provider

I have a FileBasedProject with :

  • Language pair: "de-DE" to "en-GB".
  • One file "fruits.xml".
  • One DeepL MT Translation Provider.

Screenshot of Studio Developers Q&A project settings showing a selected DeepL Translator provider for the language pair German to English.

Attempting to run the following code via the API completes without errors but does not pre-translate the file (no translations in the target segment):

    FileBasedProject ThisSdlProject = new FileBasedProject(SdlProjectFilePath);
    
    var settings = ThisSdlProject.GetSettings();
    var preTranslateSettings = settings.GetSettingsGroup();
    preTranslateSettings.NoTranslationMemoryMatchFoundAction.Value = NoTranslationMemoryMatchFoundAction.ApplyAutomatedTranslation;
    preTranslateSettings.TranslationOverwriteMode.Value = TranslationUpdateMode.KeepExistingTranslation;
    preTranslateSettings.MinimumMatchScore.Value = 75;
    ThisSdlProject.UpdateSettings(settings);
    
    ProjectFile[] translatableFiles = ThisSdlProject.GetTargetLanguageFiles(new Core.Globalization.Language(CultureInfo.GetCultureInfo(TargetLocale)));
    
    AutomaticTask preTranslateTask = ThisSdlProject.RunAutomaticTask(
        translatableFiles.GetIds(),
	    AutomaticTaskTemplateIds.PreTranslateFiles
    );
    
    ThisSdlProject.Save();

Screenshot of pre-translate settings with a minimum match value of 75 and options set to keep existing translation and apply automated translation when no match is found.

However, if I select the file in Studio 2021, Batch Tasks -> Pre-translate -> Finish (without changing any settings), it works:

Screenshot of 'fruits.xml' file in Studio Developers Q&A with source language German and target language English, showing untranslated words with NMT tag.

I swapped the DeepL MT Translation Provider for a File Based Translation Provider (Test_de-DE_en-GB.sdltm) and tried it again, and it worked as expected:

Screenshot of 'fruits.xml' file in Studio Developers Q&A with source language German and target language English, showing translated words with CM tag indicating confirmed matches.

Are there additional settings that must be applied in order for MT Translation Provider pre-translation to be applied via the API?

Thanks in advance,

Samuel



Generated Image Alt-Text
[edited by: RWS Community AI at 6:37 AM (GMT 0) on 15 Nov 2024]
Parents Reply Children
  • Hi Andrea,

    Thanks again for your reply.

    Already tried that, runs all the way through but does not translate the file:

    namespace Sdl.Sdk.PreTranslateFile
    {
        using Sdl.ProjectAutomation.Core;
        using Sdl.ProjectAutomation.FileBased;
        using Sdl.ProjectAutomation.Settings;
        using System;
    
        public class PreTranslateFile
        {
            public void Create(
                string SdlProjectFilePath
            )
            {
                Console.WriteLine("Define selectedProject");
                FileBasedProject selectedProject = new FileBasedProject(SdlProjectFilePath);
                Console.WriteLine("Detect selectedProject");
                if (selectedProject != null)
                {
                    Console.WriteLine("Define settings");
                    var settings = selectedProject.GetSettings();
                    Console.WriteLine("Define preTranslateSettings");
                    var preTranslateSettings = settings.GetSettingsGroup();
                    preTranslateSettings.NoTranslationMemoryMatchFoundAction.Value = NoTranslationMemoryMatchFoundAction.ApplyAutomatedTranslation;
                    preTranslateSettings.MinimumMatchScore.Value = 75;
                    Console.WriteLine("UpdateSettings");
                    selectedProject.UpdateSettings(settings);
                    Console.WriteLine("Save");
                    selectedProject.Save();
                    Console.WriteLine("Define targetFiles");
                    var targetFiles = selectedProject.GetTargetLanguageFiles();
                    Console.WriteLine("RunAutomaticTasks");
                    selectedProject.RunAutomaticTasks(targetFiles.GetIds(), new[]
                    {
                        AutomaticTaskTemplateIds.PreTranslateFiles,
                    }
                    );
                    Console.WriteLine("Save");
                    selectedProject.Save();
                }
            }
        }
    }

    Console:

    • Define selectedProject
    • Detect selectedProject
    • Define settings
    • Define preTranslateSettings
    • UpdateSettings
    • Save
    • Define targetFiles
    • RunAutomaticTasks
    • 2021-06-28 12:48:54,762 [1] INFO ContentProcessingTaskImplementation [(null)] - Batch task max thread count = 3
    • Save
  • Hi Samuel,

    I've managed to reproduce the problem, the credentials are not sent to DeepL service and this is why the pre-translation is not working. If you open Fiddler you'll see that once the pre-translate is hit from DeepL service you'll receive 403.

    While I've investigated this problem I've discovered a small bug in DeepL translation provider in the way we are storing the options. They should be saved in the state of the provider and not in the provider URI, this is why Studio is not able to take the credentials from the Credentials Store.

    We are working to fix the problem in the DeepL plugin however it will take some time to test the new version and publish it on the AppStore.

    In the meantime the workaround for that it will be to add the DeepL Translation provider to the project programmatically (please make sure the project doesn't already have the DeepL added in Settings):

    var studioProject =
    new FileBasedProject(
    @"path to yout projectj");
    var settings = studioProject.GetSettings();

    var preTranslateSettings = settings.GetSettingsGroup<TranslateTaskSettings>();

    preTranslateSettings.NoTranslationMemoryMatchFoundAction.Value = NoTranslationMemoryMatchFoundAction.ApplyAutomatedTranslation;
    preTranslateSettings.MinimumMatchScore.Value = 75;
    studioProject.UpdateSettings(settings);
    studioProject.Save();

    var tpConfig = studioProject.GetTranslationProviderConfiguration();

    var tpUriString = "deepltranslationprovider:///";
    var tpReference = new TranslationProviderReference(new Uri(tpUriString), null, true);
    var tpCascadeEntry = new TranslationProviderCascadeEntry(tpReference, true, true, false);
    tpConfig.Entries.Add(tpCascadeEntry);
    studioProject.UpdateTranslationProviderConfiguration(tpConfig);

    var apiKey = "DeepL Api Key";
    studioProject.Credentials.AddCredential(new Uri(tpUriString), apiKey);
    var targetFiles = studioProject.GetTargetLanguageFiles();
    studioProject.Save(); var test = studioProject.RunAutomaticTasks(targetFiles.GetIds(), new[]
    {
    AutomaticTaskTemplateIds.PreTranslateFiles,
    });
    studioProject.Save();

  • Hi Andrea,

    Tomasz from XTRF here, we also came across this error and find your explanations very helpful.

    If you can, could you please share where to access the logs that you used to locate the source of error?

    It could prove useful in future.

    Kind Regards

  • Hi Andrea,

    Thanks for this, it's been driving me a bit mad!

    So as it stands, until a new DeepL plugin is developed, we must add the DeepL MT Translation Provider and pre-translate the file(s) at the same time.

    Thanks for figuring it out and good luck with the plugin development.

    Kind regards

    Samuel

  • Hi Tomasz,

    I didn't use any log file, this is how I've troubleshot:

    1. For the first part of the investigation, I've used Fiddler to see if I received something from DeepL Service when the plugin tries to access the service. There I saw that the response is 403 and in the header the API key parameter is empty. (Even if I set the API key in the Studio project used for pre-translate).
    2. That being said I've tried to set programmatically the credentials on the project because I thought that the credentials are not taken from the Credential Store when we are using a stand-alone app. Even after I programmatically added the credentials to the project I still received 403 and the key wasn't retrieved.
    3. Credentials are retrieved based on the provider URI, the only difference which I saw was: when we created an empty project and adding the provider programmatically the provider URI used was "deepltranslationprovider:///". When the provider was added via Studio interface I saw in the plugin that is the URI received also contains the options selected (because we used the provider URI to save the options selected and then populate the UI accordingly).

    I hope this will help you. If you have more questions don't hesitate to ask.

    Have a nice day,

    Andrea