This sample shows how to translate incoming and outgoing text using a custom middleware and the Microsoft Translator Text API.
In this sample, we create a simple hotel reservation bot that uses LUIS and Microsoft Translator to provide multilingual abilities to bots without the need to train different models for LUIS, the sample intoduces a wrapper around the raw translation API that can provide some customizations to the sample like :
- no-translate-list of patterns that the user doesn't want to translate
- a custom configured language vocab dictionary that is used to override the raw translation for some vocab with a predfined user translations. We also use two middlewares to intercept and handle the requests for the bot, LuisRecognizerMiddleware and TranslationMiddleware
- Clone the repository
git clone https://github.com/Microsoft/botbuilder-samples.git
- Navigate to LUIS Portal
- Click the
Sign in
button - Click on
My apps
button - Click on
Import new app
- Click on the
Choose File
and select HotelReservation.json from thebotbuilder-samples\experimental\csharp_dotnetcore\multilingual-luis-bot\Dialogs\HotelReservation\
folder. - Update BotConfiguration.bot file with your AppId, SubscriptionKey, Region and Version.
You can find this information under "Manage" tab for your LUIS application at LUIS portal.
- The
AppID
can be found in "Application Information" - The
SubscriptionKey
can be found in "Keys and Endpoints", under theKey 1
column - The
region
can be found in "Keys and Endpoints", under theRegion
column
- The
-To consume the Microsoft Translator Text API, first obtain a key following the instructions in the Microsoft Translator Text API documentation.
Paste the key in the translationKey
placeholder within the appsettings.json file.
(Optional) edit in customizable no-translate-patterns and language dictionary to give your bot translations more customization according to your scenario
- File -> Open bot and navigate to
botbuilder-samples\experimental\csharp_dotnetcore\multilingual-luis-bot\Dialogs\HotelReservation\
folder - Modify in patterns.json and/or dictionary.json to enrich your customizations.
- (Optional) Install the LUDown here to help describe language understanding components for your bot.
- (Optional) Install the Chatdown here to generate a .transcript file from a .chat file to generate mock transcripts.
- Navigate to the
botbuilder-samples\experimental\csharp_dotnetcore\multilingual-luis-bot\
and open MultilingualLuisBot.csproj in visual studio - Hit F5
- Open
botbuilder-samples\experimental\csharp_dotnetcore\multilingual-luis-bot\
sample folder. - Bring up a terminal, navigate to multilingual-luis-bot folder
- type 'dotnet run'
Microsoft Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.
- Install the Bot Framework emulator from here
- Launch the Bot Framework Emulator
- File -> Open bot and navigate to
botbuilder-samples\experimental\csharp_dotnetcore\multilingual-luis-bot\
folder - Select BotConfiguration.bot file
You can use the MSBot Bot Builder CLI tool to clone and configure any services this sample depends on.
To install all Bot Builder tools -
Ensure you have Node.js version 8.5 or higher
npm i -g msbot chatdown ludown qnamaker luis-apis botdispatch luisgen
To clone this bot, run
msbot clone services -f deploymentScripts/msbotClone -n <BOT-NAME> -l <Azure-location> --subscriptionId <Azure-subscription-id>
Language Understanding service (LUIS) allows your application to understand what a person wants in their own words. LUIS uses machine learning to allow developers to build applications that can receive user input in natural language and extract meaning from it.
Bot translator allows your application to support multiple languages without an explicit need to train different language understanding models for each language.