Get-DeepLtranslation translating straight from your powershell

tt
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 https://www.deepl.com/translator

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.

function get-DeepLtranslation ($sentence, $fromLang, $toLang)
{
#Languages available: PL,EN,NL,ES,IT,FR
$url = "https://www.deepl.com/jsonrpc"
$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()
$stream.Write($bytes,0,$bytes.Length)
$stream.close()
$reader = New-Object System.IO.Streamreader -ArgumentList $web.GetResponse().GetResponseStream()
$answer = ($reader.ReadToEnd()|ConvertFrom-Json).result.translations.beams | select -ExpandProperty 'postprocessed_sentence'
$reader.Close()
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)

2t

When put in sentence that will work.

3t

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

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

https://dict.deepl.com/polish-english/search?ajax=1&query=jab%C5%82ko&source=polish&onlyDictEntries=1&translator=dnsof7h3k2lgh3gda&delay=300&jsStatus=0&kind=full&eventkind=keyup&forleftside=true

calls. Behind it’s this :

https://dict.deepl.com/english-polish/search?source=auto&query=%C5%82%C3%B3d%C5%BA

So you can get the translation like this:

(Invoke-WebRequest -Uri ‘https://dict.deepl.com/polish-english/search?ajax=1&query=jab%C5%82ko&source
=polish&onlyDictEntries=1&translator=dnsof7h3k2lgh3gda&delay=300&jsStatus=0&kind=full&eventkind=keyup&forleftside=true’).links[0].outerText
jabłko

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.

Advertisements