It is currently Tue Oct 22, 2019 12:15 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Deepl.com - Automated Translation (Windows)
PostPosted: Thu Oct 26, 2017 12:15 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1102
Location: Germany::Berlin()
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.):
Code:
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]


Here the PB code to call this ps1 file to translate:
Code:
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


Note: If someone wants to translate the PowerShell code to PB code, please post here. :)

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Deepl.com - Automated Translation (Windows)
PostPosted: Thu Oct 26, 2017 6:07 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4365
Location: Germany
Have you seen this:

viewtopic.php?f=13&t=69248

Bernd


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye