In this tutorial we'll be explained how to insert a Tag in Translation Unit. At this point we assume the user knows how to set up the project and how to implement Segment Element Visitor pattern.
For more information about the Segment Element Visitor please read first this tutorial.
Please keep in mind this tutorial will modify your Translation Memory and this might produce unwanted results.
Complete sample code can be found on Github.
What we want to achieve:
How to create a new Tag and insert it in Translation Unit
- Open the Translation Memory
- Get all Translation Units
- For each translation unit get source segment elements:
translationUnit.SourceSegment.Elements.ToList()
Bellow you can see an example in Debugger how elements from source segment looks like:
For example if we want to replace the email address at position 4 with a tag we need to do the following:
- Create new tag like this
- Remove the original element:
translationUnit.SourceSegment.Elements.RemoveAt(4)
; - Insert at the same index the tag created before:
translationUnit.SourceSegment.Elements.InsertRange(4, tag)
; - Update the translation unit:
tm.LanguageDirection.UpdateTranslationUnit(translationUnit);.
For more complex example segment element visitor pattern should be used.