Last active
August 27, 2018 03:38
-
-
Save darrenjrobinson/0930c83c7bb8279daa92a6bff3e60b6a to your computer and use it in GitHub Desktop.
Azure Cognitive Services Text Language Translation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# API Key from https://azure.microsoft.com/en-us/services/cognitive-services/translator-text-api/ | |
$apiKey = "yourAPIKey" | |
# Translation API | |
$translateBaseURI = "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0" | |
# Convert from - en = English | |
$fromLang = "en" | |
# Supported Languages https://docs.microsoft.com/en-us/azure/cognitive-services/translator/languages | |
# Convert to - de = German | |
$toLang = "de" | |
# API Auth Headers | |
$headers = @{} | |
$headers.Add("Ocp-Apim-Subscription-Key",$apiKey) | |
$headers.Add("Content-Type","application/json") | |
# Conversion URI | |
$convertURI = "$($translateBaseURI)&from=$($fromLang)&to=$($toLang)" | |
# Text to Convert | |
$textToConvert = "This text has been converted from English to German using Azure Cognitive Services" | |
# Build Conversion Body | |
$text = @{'Text' = $($textToConvert)} | |
$text = $text | ConvertTo-Json | |
# Convert | |
$conversionResult = Invoke-RestMethod -Method POST -Uri $convertURI -Headers $headers -Body "[$($text)]" | |
write-host -ForegroundColor 'yellow' "'$($textToConvert)' converted to '$($conversionResult.translations[0].text)'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment