Translate text with PowerShell and Google Translate

I was struggling with a Windows licensing topic and as it turns out, Microsoft it’s designing some tools to be language dependent in terms of output (i’ll do a separate blog post regarding this). There were many ideas on how to tackle the problem, but afterwards I thought “hey, I don’t have complicated sentences and maybe a Google translation just might be enough).

Browsing the web I found a Google Translate endpoint which doesn’t require API keys (as you might know, Google is demanding an API key in order to use the translate service).

As it turns out, it’s not that complicated, just be aware that the call to the endpoint must be done via REST with GET. The code for this is:

 

$Text = “Hi there!, My name is Alex.”

$TargetLanguage = “de”
$Uri = “https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$($TargetLanguage)&dt=t&q=$Text”
$Response = Invoke-RestMethod -Uri $Uri -Method Get

$Translation = $Response[0].SyncRoot | foreach { $_[0] }

write-host $Translation

 

 

I will return with an article where I use this method to translate the slmgr.vbs output to english.

Leave a comment

Your email address will not be published. Required fields are marked *

eighteen − fourteen =