In this page we'll explain how to edit an sdlxliff from selected project in Batch Task plugin context. Like in previous documentation we'll also use Project Anonymizer plugin for code example. Full source code of the project can be found here .
When we want to edit an sdlxliff file we need a BilingualProcessor.
How to create a Bilingual Processor
1. Create a new class which inherits AbstractBilingualContentProcessor class.
2. Override ProcessParagraphUnit() method.
Once we created the processor we need to add it to IMultiFileConverter object from ConfigureConverter method.
Please make sure you override OnFileComplete() method in your application. If you don't override this method your changes on the file will not be saved.
In the processor class appears following object SegmentVisitor(). In order to read the information from each segment you need implement visitor pattern.
How to implement Visitor Pattern
1. Create a class which implements IMarkupDataVisitor interface.
2. Create a method which receive an ISegment object as parameter like this:
public void VisitTextMethod(ISegment segment)
{
VisitChildren(segment);
}
Where VisitChildren() has the following implementation:
private void VisitChildren(IAbstractMarkupDataContainer container)
{
if (container == null)
return;
foreach (var item in container.ToList())
{
item.AcceptVisitor(this);
}
}
3. Call VisitChildren() from VisitSegment() method like this:
public void VisitSegment(ISegment segment)
{
VisitChildren(segment);
}
4.
The last step is to add a implementation to VisitText() method. This method is fired automatically when we have a text in the segment.
public void VisitText(IText text)
{
text.Properties.Text = "New text we add to segment"
}
More logic should be added in your implementation which will fit your needs. In the above example for each segment from your file will contains only this "New text we add to segment".