Batch API: How to modify sdlxliff file

So I created a batch task that loops through all the segments in an sdlxliff file.

Here is some example code:


The Task:

    public class TranslateTask : AbstractFileContentProcessingAutomaticTask
    {
        protected override void ConfigureConverter(ProjectFile projectFile, IMultiFileConverter multiFileConverter)
        {
		multiFileConverter.AddBilingualProcessor(new SegmentProcessor());
        }
    }

 

The Processor:

public class SegmentProcessor : AbstractBilingualContentProcessor
{
	public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
	{
	    if (paragraphUnit.IsStructure)
	    {
	        return;
	    }

	    foreach (var segmentPair in paragraphUnit.SegmentPairs)
	    {
	        if (IgnoreSegment(segmentPair))
	        {
	            continue;
	        }

// The following code DOES NOT WORK. Casting to Itext return null. foreach (var target in segmentPair.Target) { var text = target as IText; if (text != null) { text.Properties.Text = "Updated"; } } } } }

 

Question:

Is there a simple way to update the Target text in each segment pair?

If there isn't. What do I need to do to accomplish this?

Parents
  • Indeed in my example I'm updating the active document. Initially I thought that you where asking about how to change the target but didn't realize you wanted to save the changes. To update the content of the original stream using the batch task API you need to do the following:

    1. Wrap your bilingual content processor inside BilingualContentHandlerAdapter. This will save you from making your own implementation of writing the sdlxliff

    multiFileConverter.AddBilingualProcessor(new BilingualContentHandlerAdapter(new SegmentProcessor()));

    2. Instruct the framework that you made changes to the original stream. This is done by overriding the  OnFileComplete on your custom task class

     public override bool OnFileComplete(ProjectFile projectFile, IMultiFileConverter multiFileConverter)
    {
        return true;
    }

     Hope this helps.

    Romulus Crisan | Translation Productivity Development Manager | SDL | (twitter) @cromica_82 | (blog) http://www.romuluscrisan.com/

Reply
  • Indeed in my example I'm updating the active document. Initially I thought that you where asking about how to change the target but didn't realize you wanted to save the changes. To update the content of the original stream using the batch task API you need to do the following:

    1. Wrap your bilingual content processor inside BilingualContentHandlerAdapter. This will save you from making your own implementation of writing the sdlxliff

    multiFileConverter.AddBilingualProcessor(new BilingualContentHandlerAdapter(new SegmentProcessor()));

    2. Instruct the framework that you made changes to the original stream. This is done by overriding the  OnFileComplete on your custom task class

     public override bool OnFileComplete(ProjectFile projectFile, IMultiFileConverter multiFileConverter)
    {
        return true;
    }

     Hope this helps.

    Romulus Crisan | Translation Productivity Development Manager | SDL | (twitter) @cromica_82 | (blog) http://www.romuluscrisan.com/

Children