In this tutorial will be explained how to open a Translation Memory using Translation Memory API and how to implement Segment Element Visitor Pattern. Complete sample code can be found on Github.
Please keep in mind this will modify your Translation Memory and this might produce unwanted results.
In order to manipulate TMs we need to add references to following libraries: Sdl.LanguagePlatform.TranslationMemory.dll and Sdl.LanguagePlatform.TranslationMemoryApi.dll.
After we open the tm we get all the Translation Units associated to that tm.
var tm =new FileBasedTranslationMemory(tmPath);
var tmIterator = new RegularIterator();
var tus = tm.LanguageDirection.GetTranslationUnits(ref tmIterator);
In tus variable we have all the translation units from the tm.
How to implement Segment Element Visitor Pattern
- Create a class which implements ISegmentElementVisitor interface
- In VisitText() method will be fired when the segment contains plain text. You can read the segment text like this text.Value();
- In VisitTag() method can be read information about tags.