Search code examples
azure-cognitive-servicesmicrosoft-translator

Translation with XML-like tags on Microsoft Cognitive Service


I am trying to translate on Microsoft Cognitive Service text with XML-like tags:

<LABEL0>John</LABEL0> <LABEL1>Smith</LABEL1> is reading a <LABEL2>blue book</LABEL2>.

I am wondering if this is something that the NMT service would be able to handle and conserve tags in the translation?

Thanks


Solution

  • You can preserve your XML tags by specifying a textType parameter of "html" on the request. See here for the spec.

    https://dev.microsofttranslator.com/translate?api-version=3.0&from=en&to=fr&category=generalnn&textType=html
    

    For example, your sentence with textType set to html, translated to French produces

    <LABEL0>John</LABEL0> <LABEL1>Smith</LABEL1> lit un <LABEL2>livre bleu</LABEL2>