Custom batch pre-translationfuction skipping segment or missing result

When I develop a plugin use the Batch task API ,I custom a batch pre-translation function,but when I send the source text to translation engine to ask for the result ,The result is not inserted into the corresponding segment or the result is missing.  I want to know the reason.

  • You need to set this value:

    Trados Studio options menu with Translation Memory and Automated Translation settings, highlighting 'Concordance search fuzzy threshold' field with a red arrow pointing to it.



    Generated Image Alt-Text
    [edited by: Trados AI at 1:22 PM (GMT 0) on 5 Mar 2024]
  • Thans for your reply.

    But the problem is not solved.

    My problem is "when I send the source text into translation engine ask for result by batch task,I can get the translation result ,but The translation result is not inserted into the corresponding segment or some translation result is missing.

    For example 

    The translation result of source segment 2 is inserted into the translation result segment 3.

  • I doubt anyone can answer this without seeing your code to see where you have gone wrong.  Can you share the code for this part?

  • Hi ,

    Can you please take a look at DeepL translation provider code sample? Maybe is something which is not set in your plugin.

    Kind regards,

    Andrea Ghisa

  • Deer Paul

    The code is as follow:WIll you please give me some advice about the code? Thanks. 

    public void TranslateBatch2()
    {
    if (this.segPairs_in_batch.Count <= 0)
    return;
    Itranlate tranlate = GetTranlate();
    string[] txttobetranslated = new string[this.segPairs_in_batch.Count];
    string[] splitArr = new string[this.segPairs_in_batch.Count];
    string translateStr = "";
    string spaceSplit = "";//分割符
    switch (this.__setings.useOperType)
    {
    case "1"://爱词霸
    spaceSplit = "555";
    break;
    case "2"://百度
    spaceSplit = "{{8}}";
    break;
    case "3"://谷歌
    spaceSplit = "{{8}}";
    break;
    case "4"://搜狗
    spaceSplit = "AKA8AKA";
    break;
    case "5"://腾讯
    spaceSplit = "{{8}}";
    break;
    case "6"://有道
    spaceSplit = "{}";
    break;
    }
    int total = 0;
    TagProcessor[] tagProcessorArray = new TagProcessor[this.segPairs_in_batch.Count];
    try
    {
    for (int index = 0; index < this.segPairs_in_batch.Count; index++)
    {
    var a = new TagProcessor(new Segment(this.SourceLang.CultureInfo), true, null, this.SourceLang.UseBlankAsWordSeparator, this.SourceLang.CultureInfo, this.TargetLang.UseBlankAsWordSeparator);
    tagProcessorArray[index] = a;

    var txt2 = BatchTranslatorProcessor.GetPlainTextFromSegment(this.segPairs_in_batch[index].Source);
    var txt1 = tagProcessorArray[index].ReplaceSrcTextWithTargetTextDirectly(txt2);
    var txt0 = tagProcessorArray[index].ReplaceSourceTextwithTags(txt1);
    txttobetranslated[index] = txt0;
    total += a.GetWordCount(txt0, false);

  • Deer

    The code is as follow:Will you please give me some advice.

    public void TranslateBatch2()
    {
    if (this.segPairs_in_batch.Count <= 0)
    return;
    Itranlate tranlate = GetTranlate();
    string[] txttobetranslated = new string[this.segPairs_in_batch.Count];
    string[] splitArr = new string[this.segPairs_in_batch.Count];
    string translateStr = "";
    string spaceSplit = "";//分割符
    switch (this.__setings.useOperType)
    {
    case "1"://爱词霸
    spaceSplit = "555";
    break;
    case "2"://百度
    spaceSplit = "{{8}}";
    break;
    case "3"://谷歌
    spaceSplit = "{{8}}";
    break;
    case "4"://搜狗
    spaceSplit = "AKA8AKA";
    break;
    case "5"://腾讯
    spaceSplit = "{{8}}";
    break;
    case "6"://有道
    spaceSplit = "{}";
    break;
    }
    int total = 0;
    TagProcessor[] tagProcessorArray = new TagProcessor[this.segPairs_in_batch.Count];
    try
    {
    for (int index = 0; index < this.segPairs_in_batch.Count; index++)
    {
    var a = new TagProcessor(new Segment(this.SourceLang.CultureInfo), true, null, this.SourceLang.UseBlankAsWordSeparator, this.SourceLang.CultureInfo, this.TargetLang.UseBlankAsWordSeparator);
    tagProcessorArray[index] = a;

    var txt2 = BatchTranslatorProcessor.GetPlainTextFromSegment(this.segPairs_in_batch[index].Source);
    var txt1 = tagProcessorArray[index].ReplaceSrcTextWithTargetTextDirectly(txt2);
    var txt0 = tagProcessorArray[index].ReplaceSourceTextwithTags(txt1);
    txttobetranslated[index] = txt0;
    total += a.GetWordCount(txt0, false);

  • Deer 

    The related code is as follow:

    public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
    {

    int num = 9;
    if (paragraphUnit.IsStructure)
    {
    base.ProcessParagraphUnit(paragraphUnit);
    }
    else
    {
    using (IEnumerator<ISegmentPair> enumerator = paragraphUnit.SegmentPairs.GetEnumerator())
    {
    while (enumerator.MoveNext())
    {
    ISegmentPair current = enumerator.Current;
    //if (!current.Properties.IsLocked && !this.IsTargetEmpty(current) && (this.__setings.IsBatchChangeStatus && current.Target.Properties.TranslationOrigin.OriginType == "mt"))
    //{
    // current.Target.Properties.TranslationOrigin.OriginType = "Interact";
    //}
    ////else if (!current.Properties.IsLocked && this.IsTargetEmpty(current) && (string.IsNullOrEmpty(BatchTranslatorProcessor.GetPlainTextFromSegment(current.Target)) || string.IsNullOrWhiteSpace(BatchTranslatorProcessor.GetPlainTextFromSegment(current.Target))))
    //else if (!current.Properties.IsLocked )
    //{
    string empty = string.Empty;
    string plainTextFromSegment;
    try
    {
    plainTextFromSegment = BatchTranslatorProcessor.GetPlainTextFromSegment(current.Source);
    }
    catch (Exception ex)
    {
    continue;
    }

    if (!string.IsNullOrWhiteSpace(plainTextFromSegment) && !string.IsNullOrEmpty(plainTextFromSegment))
    {
    //this.segPairs_in_batch.Add(current);
    //this.TranslateBatch();