Sdl.LanguagePlatform.Core.SegmentElement <--> System.Xml.Linq.XElement ?

Hello all!  [EDIT: Split into two posts, clarified this issue]

I am developing a plugin for Trados Studio (an implementation of ITranslationProvider in C#) that sends text to our webservice for automated translation.

The prototype plugin that I took over from a predecessor extracts only plain text from source segments. I have to enhance it to send intact tags, but am not getting anywhere at the moment.  As I understand the situation, I have to convert each SegmentElement on the input side to an XElement (alternatively directly to an XML string), and afterwards convert the webservice's parsed XML answer back into a series of SegmentElements. (I have tried returning a plain XML string, but in the editor I just see it verbatim, so Trados clearly doesn't recognize the XML tags as proper tags on its own.)

HOW do I do this? I am sure there is a way, but I can't seem to find any fitting API call, let alone an explanation or sample project.

I'd be very grateful indeed for any advice and pointers!

Best regards,

Sebastian

Parents
  • Hi Sebastian,

    Have you taken a look at the Tag object in the SDK documentation?  It looks like you have to create a new Tag object based on the markup sent back from your server.

    Best regards,

    Patrick Porter

  • Thank you Patrick! That does look like the plausible component, doesn't it?

    What I don't know yet is what the transformation from the server response to Tag constructor arguments is supposed to look like, and even less, what processing will be needed with an XML response containing several tags.

    I am already stumped one step earlier, though, in the transformation _from_ SDL elements. I have a hunch that a solution here will inform me considerably on the reverse transformation.

    I have an ISegmentElementVisitor implementation like in the sample app, which doesn't yield proper tags.

    The method for a TagToken looks like this at present, for instance:

           public void VisitTagToken( Sdl.LanguagePlatform.Core.Tokenization.TagToken token ) {

               _text += token.Tag; // I've tried all the operations I could think of: token.Tag.TextEquivalent, token.ToString(), ...

           }

    The closest thing to a tag-like output was something like "<1 x=1 id=ph22 text-equiv="0x1"/>" (for something that in the editor looks like <field id="1" value="0x1"/>). I don't quite believe that this is what an exported tag is supposed to look like!

    Have you got any idea what I am missing here?

    Thanks, Sebastian

  • Hi Sebastian,

    That is in fact what the tag markup will look like, even though the value in the editor is different.  It seems that this has something to do with the way that the tags are stored in the sdlxliff file.  There is a sort of index of the different tags, and in the underlying xml for each segment, instead of the text that you would see in the editor, the tags get an "id", if you look in the xml of the sdlxliff for that tag id, you will see a listing that contains the info.  I'm not really sure the reason for handling them that way, but if you create a tag with that same markup and other properties, Studio will handle it properly.

    I hope that helps.

  • Hi Patrick,

    I am still making progress on this matter, and I just want to thank you and let you know that your input has helped me tremendously. Now I know that that weird output is indeed what I have to work with/around (having some trouble with XML parsers choking on non-alphanumeric tags, but I'm sure I'll get there).

    Wishing you an enjoyable weekend!

Reply Children
No Data