Deepl.com - Automated Translation (Windows)
Posted: Thu Oct 26, 2017 12:15 pm
Hello,
Deepl.com is very good and is better than Google Translator.
My WinAPI Library is available in four languages and the texts were translated automatically with Google Translator.
Because Deepl.com is good, I translate the texts with Deepl.com later.
On following page there is a solution with PowerShell to send the text to website via JSON: https://psvmware.wordpress.com/2017/09/ ... owershell/
I changed the code so that you can pass parameters to the function (I'm a beginner in Powershell.):
Here the PB code to call this ps1 file to translate:
Note: If someone wants to translate the PowerShell code to PB code, please post here. 
Deepl.com is very good and is better than Google Translator.
My WinAPI Library is available in four languages and the texts were translated automatically with Google Translator.
Because Deepl.com is good, I translate the texts with Deepl.com later.
On following page there is a solution with PowerShell to send the text to website via JSON: https://psvmware.wordpress.com/2017/09/ ... owershell/
I changed the code so that you can pass parameters to the function (I'm a beginner in Powershell.):
Code: Select all
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
}
get-DeepLtranslation -sentence $args[0] -fromLang $args[1] -toLang $args[2]
Code: Select all
EnableExplicit
Define Program
Define PSFile$ = "C:\...\File.ps1"
Define Sentence$ = "Hello world"
Define FromLang$ = "EN"
Define ToLang$ = "FR"
Program = RunProgram("cmd.exe", "/c PowerShell.exe -Command " + Chr(34) + PSFile$ + Chr(34) + " '" + Sentence$ + "' '" + FromLang$ + "' '" + ToLang$ + "'", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
If Program
While ProgramRunning(Program)
If AvailableProgramOutput(Program)
Debug ReadProgramString(Program)
;Break;If you want to read the first line
EndIf
Wend
CloseProgram(Program)
EndIf