Due to essential maintenance, access to Trados cloud will be unavailable on Saturday 30 August from 00:00 to 12:00 UTC.

Trados Studio 2024: SearchSegment is called multiple times for a single active segment, and provider cannot access active/neighbor segments’ context?

Context
I’m developing a custom MT translation provider plug-in for Trados Studio 2024 (Studio18).
The provider implements ITranslationProvider and ITranslationProviderLanguageDirection, and returns SearchResults from SearchSegment.


Environment
• Trados Studio: 18.0.1.2259 (Studio18)
• Sdl.Core.PluginFramework.Build: 18.0.1
• .NET Framework: 4.8
• OS: Windows 10 Enterprise
• Language pair: ja-JP → en-US


Goal
I want to build a context-aware MT provider that uses surrounding segments (previous/next) to improve translation quality during interactive editing in the Studio editor.


Observations
• When the first segment becomes active in the editor, SearchSegment is called multiple times (4+), even without navigating to another segment.
• The API does not expose which segment is currently active, nor does it allow querying adjacent segments from within SearchSegment.
• I also observe parallel calls on different threads, and calls for the next segment (likely prefetch), which I assume are part of editor optimizations.


Minimal code surface
• SearchSegment signature I use: public SearchResults SearchSegment(SearchSettings settings, Segment segment)
• I log each invocation with a correlation id and thread id. Example excerpt: [DEBUG] SearchSegment start. mode=NormalSearch, sourceText(len)=29 [DEBUG] SearchSegment start. mode=NormalSearch, sourceText(len)=36
• GetLanguageDirection is also called repeatedly; I cache the language direction instance on my side.


What I expected
• Either a way to:
• Know which segment is currently active in the editor (e.g., an index/id or context object), and/or
• Retrieve adjacent segments (previous/next) from within SearchSegment for better context handling,
• Or official guidance on the intended pattern to access reliable context for interactive MT in the editor.


What I tried already
• Implemented only SearchSegment for interactive use (SearchSegments is used in batch; I can see order there).
• Confirmed SupportsTranslation = true; removed all NotImplementedException from the pipeline methods.
• Added logging; observed that SearchSegment is invoked multiple times for what appears to be the active segment and also for its neighbor (prefetch).
• Considered heuristics (thread-local last query cache), but they are not reliable because of prefetch and parallel execution.


Questions
1. Is it expected that SearchSegment is called multiple times for a single active segment and also for neighboring segments (prefetch) in the editor?
2. Is there any supported API to:
• Identify which segment is currently active in the editor from within SearchSegment?
• Retrieve previous/next segment text (or broader paragraph context) during interactive translation?
3. If direct editor context is not available by design, what are the recommended best practices for building a context-aware MT provider in Studio (e.g., leveraging structure context, different interfaces, or another extension point)?
4. Are there sample providers or documentation that demonstrate accessing reliable context during interactive editing?


Thanks in advance for any pointers or references to official docs/samples.

Parents
  • Hi  ,
    I tried to do the same thing that you did a few weeks ago and I faced the same difficulties.


    1. The multiple calling of SearchSegment has to do with the LookAhead functionality ( I thought it was rather difficult to find the documentation for this ).
    In Trados Studio go to File -> Editor -> Automation (-> Translation Memory) and disable the "Enable LookAhead" functionality.
    You can not disable this funcitonality from within your plugin. You need to do it manually. See this question: https://community.rws.com/developers-more/trados-portfolio/trados-studio-developers/f/sdk_qa/58407/gettin-application-settings-in-plugin

    2. Yes this is possible, but not within SearchSegment (again the documentation is horrible). In your ITranslationProvider implementation you need to make sure that SupportsSearchForTranslationUnits is true.

    public bool SupportsSearchForTranslationUnits
    {
        get { return true; }
    }

    Then in your ITranslationProviderLanguageDirection implementation you need to implement SearchTranslationUnit(SearchSettings settings, TranslationUnit translationUnit). This is now called instead of SearchSegment.
    The TranslationUnit has an id you can get with 

    translationUnit.DocumentSegmentPair.Properties.Id

    Then you need to find the index of the segment with that id in all the SegmentPairs of the editor (i didn't find a better solution than this:)

    SegmentId documentSegmentPairId = translationUnit.DocumentSegmentPair.Properties.Id;
    EditorController editorController = SdlTradosStudio.Application.GetController<EditorController>();
    if(editorController.ActiveDocument != null)
    {
        IEnumerable<ISegmentPair> segmentPairs = editorController.ActiveDocument.SegmentPairs;
        if (segmentPairs != null)
        {
            List<ISegmentPair> segmentPairsList = segmentPairs.ToList();
            int indexOfId = segmentPairsList.FindIndex(sp => sp.Properties.Id.Equals(documentSegmentPairId));
        }
    }

    With that index you can get the stuff before and after.

    Best Regards
    Lukas 

Reply
  • Hi  ,
    I tried to do the same thing that you did a few weeks ago and I faced the same difficulties.


    1. The multiple calling of SearchSegment has to do with the LookAhead functionality ( I thought it was rather difficult to find the documentation for this ).
    In Trados Studio go to File -> Editor -> Automation (-> Translation Memory) and disable the "Enable LookAhead" functionality.
    You can not disable this funcitonality from within your plugin. You need to do it manually. See this question: https://community.rws.com/developers-more/trados-portfolio/trados-studio-developers/f/sdk_qa/58407/gettin-application-settings-in-plugin

    2. Yes this is possible, but not within SearchSegment (again the documentation is horrible). In your ITranslationProvider implementation you need to make sure that SupportsSearchForTranslationUnits is true.

    public bool SupportsSearchForTranslationUnits
    {
        get { return true; }
    }

    Then in your ITranslationProviderLanguageDirection implementation you need to implement SearchTranslationUnit(SearchSettings settings, TranslationUnit translationUnit). This is now called instead of SearchSegment.
    The TranslationUnit has an id you can get with 

    translationUnit.DocumentSegmentPair.Properties.Id

    Then you need to find the index of the segment with that id in all the SegmentPairs of the editor (i didn't find a better solution than this:)

    SegmentId documentSegmentPairId = translationUnit.DocumentSegmentPair.Properties.Id;
    EditorController editorController = SdlTradosStudio.Application.GetController<EditorController>();
    if(editorController.ActiveDocument != null)
    {
        IEnumerable<ISegmentPair> segmentPairs = editorController.ActiveDocument.SegmentPairs;
        if (segmentPairs != null)
        {
            List<ISegmentPair> segmentPairsList = segmentPairs.ToList();
            int indexOfId = segmentPairsList.FindIndex(sp => sp.Properties.Id.Equals(documentSegmentPairId));
        }
    }

    With that index you can get the stuff before and after.

    Best Regards
    Lukas 

Children
No Data