BilingualContentProcessor returning empty file

Hello SDL and Developers,

I need to clear unlocked target segments in sdlxliff when creating a project.

I created a bilingualcontentprocessor (called "Wiper") and I ran it using File Type Framework Apis  multifileconverter.

the wiper seems to work as it writes in console for each of its steps, but at the end of the process I get an empty sdlxliff file.

The empty sdlxliff file is well formed but there's no TU in it.

the original SDLxliff file has few tus, 4 of which are unlocked and therefore processed by the wiper.

Where am I doing wrong?

 

Thank you very much for any incoming suggestion. 

 

This is the Wiper bilingualcontentprocessor

      public class Wiper : AbstractBilingualContentProcessor
        {
            public override void Initialize(IDocumentProperties documentInfo)
            {
                Console.WriteLine("MSG:::Ripulisco il file " + documentInfo.LastOpenedAsPath);
                base.Initialize(documentInfo);
            }
            public override void SetFileProperties(IFileProperties fileInfo)
            {
                Console.WriteLine("MSG:::setProp ");
                base.SetFileProperties(fileInfo);
            }
            public override void ProcessParagraphUnit(IParagraphUnit myPu)
            {
                if (!myPu.IsStructure) {
                    foreach(var myTu in myPu.SegmentPairs)
                    {
                        if (!myTu.Properties.IsLocked)
                        {
                            Console.WriteLine("Elimino " + myTu.Target.UniqueId.ToString());
                            myTu.Target.Clear();
                        }
                    }
                }
            }
            public override void Complete()
            {
                Console.WriteLine("MSG:::TuWiper Completo");
                base.Complete();
            }
            public override void FileComplete()
            {
                Console.WriteLine("MSG:::File Completo");
                base.FileComplete();
            }
        }

and i invoke it like that

    [....]

            IFileTypeManager mgr = Sdl.FileTypeSupport.Framework.Core.Utilities.IntegrationApi.DefaultFileTypeManager.CreateInstance(true);

            string bilingualFilePath = targetFiles[0].LocalFilePath;
            string outputfile = (targetFiles[0].LocalFilePath+@"new.sdlxliff");

            IMultiFileConverter conv = mgr.GetConverterToDefaultBilingual(bilingualFilePath, outputfile, null);

            conv.AddBilingualProcessor(new Wiper());
            conv.Parse();

    [...]
  • Hi Enrico,

    Pretty sure the crucial part is the ProcessParagraphUnit method. You are only outputting Locked IDs to Console but you never use _outfile.WriteLine(...) or anything.

    Unfortunately I also don't know how - or if at all - you can get the necessary content to ouput, as SegmentPair is an abstract concept that does not hold any XLIFF stucture. Also, sdlxliff needs context info and tag info etc. as output in its header.

    You might have to ditch this approach and handle the sdlxliff in a purely xml fashion. It seems that only locked segments have a  //trans-unit/sdl:seg-defs/sdl:seg/@locked attribute. Using such an XPath and removing the target node from the parent trans-unit could do it. I'm sorry that I cannot be of more help here. I find segment manipulation in Studio horrible but at the same time I am happy there are ways at all...

     

    Andreas

  • Hi Andreas,
    first of all thank you for your answer, I really appreciate the time you spent on helping me.

    In all the existing samples (i.e. Sdl-Community in github, or here in forums) nobody returns anything from ProcessParagraphUnits, I tried placing a "return;" statement with no luck, besides the ProcessParagraphUnits returns void... so you can't just return a PU.

    I found some code that creates a new pu, injects all properties and features of pu and every contained tu, and writes it to a new sdlxliff. But seems to me like using a truck to transport a toothpick, and it's quite articulate for my basic C# (and SDLSDK) knowledge.

    Fortunately I found a post by suggesting to use a BilingualContentHandlerAdapter. I studied the documentation, and it works!

    Basically the modification to the code is this:

    conv.AddBilingualProcessor(new BilingualContentHandlerAdapter(new Wiper()));

    By using the adapter, it takes charge of file writing.

    Also if you use "mgr.GetConverterToDefaultBilingual(sourcefilepath, sourcefilepath...) it seems to write everything in place without need to manually switch files. I just wonder if it could generate issues on bigger files, I hope for an answer from Romulus regarding this last doubt.

    Thank you again!