RWS Community
RWS Community
  • Site

Trados Go

Trados Studio

Trados Ignite

Trados Team

Trados Accelerate

Trados Enterprise

Trados GroupShare

Passolo

MultiTerm

RWS AppStore

Connectors

Beta Groups

Managed Translation

MultiTrans

TMS

Trados Enterprise

WorldServer

Language Weaver

Language Weaver Edge

Language Weaver Connectors

Language Weaver in Trados Studio

 

 

Content Champions

Tridion Docs

Tridion Sites

Contenta

LiveContent

XPP

Trados Go Ideas

Trados Studio Ideas

Trados Ignite Ideas

Trados GroupShare Ideas

Trados Team Ideas

Trados Team Terminology Ideas

Trados Enterprise & Accelerate Ideas

MultiTerm Ideas

Passolo Ideas

RWS Appstore Ideas

Tridion Docs Ideas

Tridion Sites Ideas

Language Weaver Ideas

Language Weaver Edge Ideas

Managed Translation - Enterprise Ideas

TMS Ideas

WorldServer Ideas

Trados Enterprise Ideas

XPP Ideas

GroupShare Developers

Language Cloud Developers

MultiTerm Developers

Passolo Developers

Trados Studio Developers

Managed Translation Developers

TMS Developers

WorldServer Developers

Tridion Docs Developers

XPP Developers

Language Combinations by Language Services

RWS Training & Certification

Style Guides

LDE Korean Vendor Support

RWS Campus

Trados Approved Trainers

Nordic Tridion Docs User Group

Tridion West Coast User Group

Community Ops

RWS Community Internal Group

AURORA

Internal Trados Ideas

Linguistic Validation

Mercury

QA Tools

RI Operational Excellence

Trados Inspired

XPP Cloud

Recognition & Reward System

RWS Community Platform Related Questions

Community Solutions Hub (Trados)

About RWS

Events

RWS Services: Train AI & others

RWS Training & Certification

To RWS Support

  • Search
  • Translate

    Detecting language please wait for.......


    Powered by
  • User
  • Site
  • Search
  • User
  • Developers
  • Trados Portfolio
  • Trados Studio Developers
  • More
  • Cancel
Trados Studio Developers

Trados Studio Developers > Studio Developers WIKI

How to insert a placeholder in Segment in Batch Task context
  • Home
  • Trados Studio developers forum
  • Studio Developers WIKI
  • Studio Developers Blog
  • More
  • Cancel
  • New
Show Translation Options

Detecting language please wait for.......


Powered by
Trados Studio Developers requires membership for participation - click to join
  • -Trados Studio API
    • Developer Licences
    • +Getting Started
    • -Knowledgebase
      • -How to...
        • How to create a project using public api
        • How to create a View plugin in Studio using WPF
        • How to sign an class library using Sdl Community key
        • -How to use Batch Tasks plugins
          • How bind a DataGridView to SettingsGroup
          • How to edit the plain text from sdlxliff in Batch Task context
          • How to insert a placeholder in Segment in Batch Task context
        • How to use Studio Ribbon Tabs
        • How to use Tell Me API
        • How to use the Studio Useful Tips service
        • +How to use the Translation Memory API
      • +Studio 2015
      • +Studio 2019
      • +Studio 2021
      • +Trados Studio 2022

How to insert a placeholder in Segment in Batch Task context

In this documentation we assume you are familiar with Batch Task plugin structure and with Visitor Pattern. More information about Visitor Pattern can be found here.

Like in previous documentation we'll also use Project Anonymizer plugin for code example. Full source code of the project can be found here . SegmentVisitor.cs class contains the algorithm which recursive searches for words inside a segment and does all the logic for replacing the data.

What we want to achieve 

Search in a segment for a particular text and transform that text in a placeholder. In our source code we use regular expressions find matches in segment text. 

Dependencies

If you don't have referenced Sdl.FileTypeSupport.Framework.BilingualApi.dll and Sdl.FileTypeSupport.Framework.NativeApi.dll please add a reference to them.

From  Sdl.FileTypeSupport.Framework.BilingualApi.dll we'll use IDocumentItemFactory interface.

From Sdl.FileTypeSupport.Framework.NativeApi.dll we'll use IPropertiesFactory interface. This two interfaces will allow is to create a placeholder object.

Brief API's concepts explications 

Each segment you see in Studio editor programmatically is in fact List<IAbstractMarkupData> . For example if in one segment you have plain text and placeholder tag the list will have one IText object and an IPlaceholderTag both interfaces inherits IAbstractMarkupData.

Because the objects you see above are interfaces we don't have access to them out of the box. This is why need to use Visitor Pattern which will loop through all the elements and if the element is a placeholder, the method VisitPlaceholderTag() will be called automatically. If the element is a text VisitText() method will be called automatically.

Bellow you can see how you have access to text property for am IText object.

How to create a Placeholder tag using public API

We assume that we want to transform the IText object from VisitText() into a placeholder. We take the text from the object, create a new placeholder using the method above. All good  but what we achieved until now is to create a new placeholder which is not added to the sdlxliff.

The tag we created must be inserted in the List<IAbstractMarkupData> on the exactly the same position where the IText is.

How replace the IText with IPlaceholder tag

Each object you receive in visitor patterns methods belongs to a "Parent", which is a IAbstractMarkupDataContainer. What we need to to:

  • take the parent container: var elementContainer = text.Parent;
  • from the parent container we need to take all the subitems : text.Parent.AllSubItems.ToList()
  • remove the element at specified position: elementContainer.AllSubItems.ToList()[postion].RemoveFromParent();
  • insert the tag in the position we removed the text : elementContainer.Insert(position, tag);

 

Tags:

batch task
Studio Documentation
Studio API
openexchange
  • Share
  • History
  • More
  • Cancel
Related
Recommended
  • Our Terms of Use
  • Copyright
  • Privacy
  • Security
  • Anti-slavery Statement
  • Cookie Notice
  • YouTube