Get-DeepLtranslation translating straight from your powershell

by Grzegorz Kulikowski

I was doing my dutch course homework today, and i found it a bit tedious to use browser for translation. This + the fact that i want to write myself some dutch-polish quiz, so i can memorize words better led me to write this tiny function.

The DeepL translator website can be found here

This is a tiny function that would just use the ‘word/1 sentence’ mode. It worked today, not sure if it will be working in later months/years. This was made in really quick/dirty way, as i still need to write my homework today 😉 I wrote it in 15 minutes, so don’t expect fireworks, it does what it does, it translates 😉 You can use different languages using variables fromLang and toLang.

[sourcecode language=”powershell”]
function get-DeepLtranslation ($sentence, $fromLang, $toLang)
#Languages available: PL,EN,NL,ES,IT,FR
$url = ""
$call = ‘{"jsonrpc":"2.0","method":"LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"’+$sentence+’"}],"lang":{"user_preferred_langs":["EN","PL","NL"],"source_lang_user_selected":"’+$fromLang+’","target_lang":"’+$toLang+’"},"priority":-1},"id":15}’
$bytes = [System.Text.Encoding]::ASCII.GetBytes($call)
$web = [System.Net.WebRequest]::Create($url)
$web.Method = "POST"
$web.ContentLength = $bytes.Length
$web.ContentType = "application/x-www-form-urlencoded"
$stream = $web.GetRequestStream()
$reader = New-Object System.IO.Streamreader -ArgumentList $web.GetResponse().GetResponseStream()
$answer = ($reader.ReadToEnd()|ConvertFrom-Json).result.translations.beams | select -ExpandProperty ‘postprocessed_sentence’
return $answer

I am not sure why it does not work with the polish single word. IT does translate it though on the website(blue)


When put in sentence that will work.


What i also saw, is that sometimes calls to are being made.

I don’t have time right now to dig into this, but for some words you can utilize those:

calls. Behind it’s this :

So you can get the translation like this:

(Invoke-WebRequest -Uri ‘

That would have to be still converted to proper polish.

I think that something is going wrong when trying to translate words that have polish ‘ogonki’, and char encoding has something to do with it.

You may also like

Leave a Reply

Chinese (Simplified)EnglishFrenchGermanHindiPolishSpanish