Search code examples
python-3.xmicrosoft-translator

How do you use the Microsoft Dynamic Dictionary with the translator API


How do you use the Dynamic Dictionary feature of the Microsoft Translator Text API with json as input? The linked documentation is very unclear.

I am following this example from Microsoft's gitHub page.


Solution

  • Combining the instructions here with the python examples with the following input

    text = "Instant dictionary: word <mstrans:dictionary translation=\"wordomatic\">word or phrase</mstrans:dictionary> is a dictionary entry."
    

    gives the following output:

    [
        {
            "translations": [
                {
                    "text": "Instant Dictionary Word wordomatic ist ein Wörterbucheintrag.",
                    "to": "de"
                }
            ]
        }
    ]
    

    So that answers this question.

    However, somehow everything before the tagged word is not translated.

    Also, translating text = "Instant dictionary: word" returns: {"translations": [{"text": "Instant Dictionary: Word","to": "de"}]}

    Whereas translating text = "Instant dictionary word" returns: {"translations": [{"text": "Instant Wörterbuchwort","to": "de"}]}

    This leads to the question: How do these words and characters change what the API returns?