Anthony Chu Contact Me

Easily Translate Conversations with Microsoft Bot Framework

Wednesday, April 20, 2016

Update February 4, 2017 - Bot Framework Version 3 removed the auto translation capability.

In previous articles, we created a bot using the Microsoft Bot Framework and Azure Functions and then added natural language processing using Microsoft Cognitive Services' LUIS (Language Understanding Intelligent Service).

Today, we'll look at how the translation capabilities automatically turn any bot into a multilingual bot. This is all built-in and we don't have to write any code at all!

Enabling Translation

The first thing we need to do is enable language translation on our bot. We do this by logging into the Bot Framework developer portal and changing the setting on our bot:

Enabling Translation in Bot Framework

Trying It Out

Let's fire up the same web chat bot we created in the previous article. The bot knows how to look up weather in a city.

It's important that we use the Bot Connector instead of the Bot Emulator to do this, as the translation is only enabled on the Connector.

To change the language, simply ask the bot in plain English. Let's switch to French...

French Translation Bot Framework

And Spanish...

Spanish Translation Bot Framework

It even works with Chinese!

Chinese Translation Bot Framework

What Really Happens

What is happening when we use another language is the Bot Connector translates incoming messages to the bot's native language, and it translates outbound messages to the language the user specified. All this happens transparently; the only difference the bot application will notice is the addition of sourceText and sourceLanguage to the incoming message...

{
    "type": "Message",
    "id": "Cbo6GbZr34W",
    "conversationId": "GbGEsf1Ry7YcFrt8e88Z0fYAwZGpf1c9DDY4nbCFBAJ7GKX",
    "created": "2016-04-21T05:51:18.3299811Z",
    "sourceText": "quelle est la meteo a vancouver canada",
    "sourceLanguage": "fr",
    "language": "en",
    "text": "What is the weather in vancouver, canada",

    // ...
}

This makes it super simple to build multilinguage bots!