Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Azure Cognitive Services Text Language Translation
# API Key from
$apiKey = "yourAPIKey"
# Translation API
$translateBaseURI = ""
# Convert from - en = English
$fromLang = "en"
# Supported Languages
# Convert to - de = German
$toLang = "de"
# API Auth Headers
$headers = @{}
# 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
You can’t perform that action at this time.