Looping through the segments of an SDLXLIFF file

Dear community members,

The question I will ask may sound stupid but I am a bit lost in the File Type Support API and a small hint would be really valuable for me.

I would like to develop a plugin which parse the SDLXLIFF file and execute some functions on the source segments. I just want to read the segments and not modify the SDLXLIFF file. I have the following code:

public void openSDLXLIFF()

        {

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

 

            string bilingualFilePath = @"C:\Test\149999b_EN_O.docx.sdlxliff";

            string outputfile = @"C:\Test\149999b_EN_Odo.docx.sdlxliff";

            Sdl.FileTypeSupport.Framework.IntegrationApi.IMultiFileConverter conv = mgr.GetConverterToDefaultBilingual(bilingualFilePath, outputfile, ConverterMessage);

            conv.AddBilingualProcessor(new AnalyseSDLXLIFF());

            conv.Parse();

       }

 And the following class implementing the AbstractBilingualContentProcessor

    class AnalyseSDLXLIFF : AbstractBilingualContentProcessor

    {

        public override void Initialize(IDocumentProperties documentInfo)

        {

            MessageBox.Show("initialize");

            base.Initialize(documentInfo);

        }

        public override void Complete()

        {

            MessageBox.Show("complete");

            base.Complete();

        }

        public override void SetFileProperties(IFileProperties fileInfo)

        {

            MessageBox.Show("props");

            base.SetFileProperties(fileInfo);

        }

        public override void FileComplete()

        {

            MessageBox.Show("filecomplete");

            base.FileComplete();

        }

 

        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)

        {

            MessageBox.Show("paragraphUnit");

            if (paragraphUnit.IsStructure == false)

            {

                foreach (ISegmentPair segmentPair in paragraphUnit.SegmentPairs)

                {

                    MessageBox.Show(segmentPair.Source.ToString());

                }

            }

        }

    }

When I execute my code, I know that my class is executed since the message box for the methods Initialize, SetfileProperties, FileComplete and Complete pop up. However, the ProcessParagraphUnit method is not executed at all.

I am not really familiar with the concept of derived classes and interfaces and I am sure that the solution to my problem is probably not complicated. But as I said, I am a bit lost in this API and help would be much appreciated.

 

Thanks in advance,

 

Regards,

 

Laurent

Parents Reply
  • Hi Laurent,

    You code is perfect. I just copy your code and change the bilingual file point to the xliff file in the sample project \de-DE\SamplePhotoPrinter.doc.sdlxliff; and also change the ConverterMessage as null because you did not provide the implementation of that function; of course also change MessageBox.Show to Console.WriteLine because my test is a standalone console app. Then running the code, I get the printed paragraphUnit call and also the segment content. There are some structural segment without segment content. All look right to me.

    Probably you first try your code with the xliff file from the sample project to see if it is a file problem.

    Regards,

    Xingzeng

Children