Question on how to proceed - editing sdlxliff files when creating a project with SDK

Hello,

I wrote a console application in visual studio c# that creates a project based on few parameters.

It's mostly similar/taken from the example in the project automation sdk documentation.

I need, after copying to target language the sdlxliff files, to process them by emptying the non-locked segments.

What would be the best (lightweight, easier) way to implement this, considering I'm in the process of creating a new project?

Looking up in this community i found some ways like:

- create a batch task

- use filetypes

- use core api and create a processor for sdlxliff files (i'm not sure this exists anymore, since the post was very very old).

- manually edit the sdlxliff files as xml (I'd really avoid this, doesn't seems proper or safe to me in case of spec changes).

I hope to get a hint from the experienced developers here. Thank you very much!

 

 

  • Hi Enrico,

    the following snippet is untested but should actually work. It makes use of Studio's editor controller, so it doesn't rely on manual XML handling of the sdlxliff:

    var pFile = _project.GetFile(fguid);
    var editController = SdlTradosStudio.Application.GetController<EditorController>();
    editController.Open(pFile, EditingMode.Translation);
    var doc = editController.ActiveDocument;
    foreach (var pair in doc.SegmentPairs)
    {
        if (!pair.Properties.IsLocked)
        {
            pair.Target.Clear();
        }
    }

    fguid is the guid of the target file, _project a FileBasedProject.

    Hope this helps.
    Andreas

  • Hello Andreas,
    Your snippet is lovely and is what i hoped for, but i get an error (object reference not set) on the editController.open() command.
    I guess it's because I'm in a console app, while the EditorController implies having some gui to work with.


    I implemented it like that:

            public bool TargetTuWiper(ProjectFile[] myFiles){
    var editController = SdlTradosStudio.Application.GetController();
    foreach (var pFile in myFiles) {
    int checkMyFile = pFile.FileTypeId.IndexOf("MemoQ");
    if (checkMyFile == 0){
    editController.Open(pFile, EditingMode.Translation);
    var doc = editController.ActiveDocument;
    foreach (var pair in doc.SegmentPairs)
    {
    if (pair.Properties.IsLocked)
    {
    pair.Target.Clear();
    }
    }
    editController.Save(doc);
    editController.Close(doc);
    }
    }
    return true; //I'll do some checks later
    }
  • Yes, my bad. The controller is only accessible from a Studio plugin, not from a console app. :-(

    If you wish to stick with a console app, you will probably need to use something like what is described in the Batch Task API .chm, section "Processing Files...".

    You'd be basically reading the sdlxliff using Bilingual API :

    public class FileReader : AbstractBilingualContentProcessor

    ...and writing a copy of it to a new file. You'd basically write everything as is 1:1 into the new file, and only where you encounter a locked segment, you'd unlock it first, then write it to the copy

    public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
    {
        if (paragraphUnit.IsStructure)
        {
            //write directly to copy
            return;
        }

        foreach (ISegmentPair item in paragraphUnit.SegmentPairs)
        {
            if (item.Properties.IsLocked)
           {
              item.Target.Clear();
            }
        }
        //write to copy
        return;
    }

    When all is done, you can overwrite the initial sdlxliff with the manipulated copy.

    This is all rather vague and I cannot test this at the moment, but I hope this gets you forward.

  • Thank you Andreas, I'm still looking up in the documentation to understand how to combine everything.

    I understood that I can create a bilingual content processor and then use it in a batch task or just calling it on premise.

    I'm looking the best way to call it on premise. Also I don't understand why I can't just modify a sdlxliff without writing the result on a new file, like it seems a bilingualcontentprocessor does in a batch task.

    I guess I have to study more. I'm on it. Thank you for your hints, You pointed me in the right direction.
  • What really I can't understand is, having a project, how do I pass the target files to the AbstractBilingualContentProcessor?

    I understood how you do this with batch tasks api, but not with just a collection of target bilingual files. And I can't find an example clear enough for me.

    Any help would be really appreciated :-)