Using Microsoft Translator to Create a Multilingual Chatbot in 5 Minutes

Bots & AI

Microsoft Translator is probably one of the most powerful and easiest to use cognitive service offered by Microsoft. Using Microsoft Translator you can translate text to and from almost any language you can imagine.

You can integrate with Microsoft Translator easily using the REST interface or using a connector for Power Apps, Power Automate, and Logic Apps meaning that both developers and non-developers can easily take advantage of the features.

The free pricing tier of Microsoft Translator will translate up to 2 million characters in a month and paid pricing tiers starting at $10/month. It’s both easy and cheap to get started… as with all Azure services though, be careful with pricing as it can explode on you if you aren’t careful.

In the video below I show you how to create a Microsoft Translator resource in Azure and create a multilingual chatbot that detects the language of your user and responds to the user in the language they used when asking a question.

In the video, I’m working off of our previously created bot using Power Virtual Agents in Teams. Please note you do NOT have to use Power Virtual Agents to utilize this functionality, it just makes it so easy to set up and demo for you folks. Also, if you have developers on staff you can easily write code to use Microsoft Translator with any non-Microsoft technology using the REST API.

Without further ado… Using Microsoft Translator to create a multilingual chatbot in 5 minutes… the video will be longer than 5 minutes because I like to talk and I have to explain things.. but yeah, it could totally be done in 5 minutes. 🙂

Using Microsoft Translator to Create a Multilingual Chatbot in 5 Minutes

There you have it! Short and sweet! How have you used Microsoft Translator in your organization? Any tips or advice for our readers?

Finally, for those developers out there using the SharePoint Framework (SPFx) here’s a quick function for you to play with that calls Microsoft Translator, please note this example does expose your API key, to keep it secret look at using the Azure Key Vault.

public translate(): void  {
    const requestHeaders: Headers = new Headers();
      requestHeaders.append("Content-type", "application/json");
      requestHeaders.append("Ocp-Apim-Subscription-Key", "<your api key goes here>");

      var body = [{
        Text: "<text to translate>"
      }];

      const postOptions: IHttpClientOptions = {
        headers: requestHeaders,
        body: JSON.stringify(body)
      };

    this.context.httpClient
    .post('https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es', HttpClient.configurations.v1,postOptions)
    .then((res: HttpClientResponse): Promise<any> => {
      return res.json();
    })
    .then((response: any): void => {
      //display translated text in the console
      console.log(response[0].translations[0].text);    
    });
  }

Comments are closed.