Microsoft Translator Service
Warning
(This API will be removed in the future. Please refer to the Microsoft Translator documentation instead.)
The Microsoft Translator Service allows you to translate text to various supported languages.
Set up Microsoft Translator Service
Signup for Microsoft Translator Service using your Microsoft Azure subscription account. There is a free trial option that allows you to translate up to 2,000,000 characters per month.
Example Syntax
// using Microsoft.Toolkit.Uwp.Services.MicrosoftTranslator;
await TranslatorService.Instance.InitializeAsync("<translator service key");
// Retrieves codes and friendly names for the languages available for text translation.
var languages = await TranslatorService.Instance.GetLanguageNamesAsync("en");
// Detects the language of a text.
var detectResult = await TranslatorService.Instance.DetectLanguageWithResponseAsync("Hello everyone!");
var detectedLanguage = detectResult.Language;
var detectedLanguageConfidence = detectResult.Score;
// Translates the text to Italian.
var translationResult = await TranslatorService.Instance.TranslateWithResponseAsync("Hello everyone!", "it");
var translatedText = translationResult.Translation.Text;
' Imports Microsoft.Toolkit.Uwp.Services.MicrosoftTranslator
Await TranslatorService.Instance.InitializeAsync("<translator service key")
' Retrieves codes and friendly names for the languages available for text translation.
Dim languages = Await TranslatorService.Instance.GetLanguageNamesAsync("en")
' Detects the language of a text.
Dim detectResult = Await TranslatorService.Instance.DetectLanguageWithResponseAsync("Hello everyone!")
Dim detectedLanguage = detectResult.Language
Dim detectedLanguageConfidence = detectResult.Score
' Translates the text to Italian.
Dim translationResult = Await TranslatorService.Instance.TranslateWithResponseAsync("Hello everyone!", "it")
Dim translatedText = translationResult.Translation.Text
Sample Project
Microsoft Translator Service Sample Page Source. You can see this in action in the Windows Community Toolkit Sample App.
Requirements
Device family | Universal, 10.0.16299.0 or higher |
---|---|
Namespace | Microsoft.Toolkit.Services |
NuGet package | Microsoft.Toolkit.Services |