microsoft / XLIFF2-Object-Model

If you’re looking to store localization data and propagate it through your localization pipeline allowing tools to interoperate then you may want to use the XLIFF 2.0 object model. The XLIFF 2.0 object model implements the OASIS Standard for the XLIFF 2.0 specification as defined at http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html.
Other
86 stars 26 forks source link

Source with HTML content #20

Closed andreinitescu closed 7 years ago

andreinitescu commented 7 years ago

I have HTML in the <source>, can the XLIFF2-Object-Model library create the XLIFF tags (<bpt> or <g>) from it?

The reason I need this is because I would like CAT tools like MemoQ or SDL Trados to display the source with the inline HTML tags like here:

http://kb.kilgray.com/admin/media_store/2/AA-00470/new_inlineTag.png

Another thing I tried is I created in Notepad a XLIFF file with source having restype='x-html' hoping that the tools will display the inline tags in their editor instead of plain text, but I didn't work:

     <trans-unit id="1" xml:space="preserve" restype='x-html'>
        <source>This is &lt;b&gt;bold&lt;/b&gt;</source>
     </trans-unit>

What's interesting is that these tools are able to show inline tags properly for HTML documents, so I'm trying to find a way to do this with XLIFF, but without having to write myself code which transforms the HTML tags into XLIFF tags

RyanKing77 commented 7 years ago

The correct way to do this in XLIFF 2.0 is to use inline content http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html#inline this is supported in the OM by the SpanningCode and StandaloneCode classes.

andreinitescu commented 7 years ago

@RyanKing77 Thanks for reply, but could you please provide an example? Let's say I have this HTML string:

string s = "This is <b>bold</b>";.

I don't understand how SpanningCode and StandaloneCode help me.

rabularca commented 7 years ago

@andreinitescu Hi Andrei,

I've worked a bit with XLIFF 2.0 so I can help you with this also. Basically, XLIFF 2.0 is a very different version than XLIFF 1.2. You should check a bit the specification and get some sample XLIFF 2.0 files to help you accustom to the standard. There are no more <bpt>/<ept> and <g> tags, but we have <sc>/<ec> and <pc> tags instead, which can indeed be created with the XLIFF2-Object-Model library.

In XLIFF 2.0, your code would be something like:

<unit id="1">
  <originalData>
    <data id="d1"> &lt;b</data>
    <data id="d2"> &lt;/b></data>
  </originalData>
  <segment>
    <source> This is <pc id="p1" dataRefStart="d1" dataRefEnd="d2">bold</pc></source>
    <target/>
  </segment>
</unit>

A very similar example can be found at part 4.7.2.3 Storage of the original data from the link RyanKing77 provided you.

With the XLIFF2-Object-Model library you can create this unit with the following code:

//we create the unit and add originalData items to it
var unit = new Unit(1);
unit.OriginalData.AddData("d1", "&lt;b");
unit.OriginalData.AddData("d2", "&lt;/b");

//we add a new segment to the unit
unit.Resources.Add(new Segment());

//we create the text before the SpanningCode
var textInSource = new PlainText("this is ");

//we create the SpanningCode and add the text inside it
var spanningCode = new SpanningCode("p1")
{
  DataReferenceStart = "d1",
  DataReferenceEnd = "d2"
};
var textInSpanningCode = new PlainText("bold");

spanningCode.Text.Add(textInSpanningCode);

//finally, we add both the text and the SpanningCode in the source element
unit.Resources[0].Source.Text.Add(textInSource);
unit.REsources[0].Source.Text.Add(spanningCode);

I didn't compile the code, but it should work (unless there are some typos I didn't catch).

I hope this helps you a bit. I haven't worked with the library for about a year now, so my memory about these things may be a bit fuzzy, but hopefully I will be corrected if I wrote something incorrect here.