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.

Parents Reply Children
  • 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?

  • 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 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();