Page 1 sur 1

Deepl.com - Traduction automatique (Windows)

Publié : jeu. 26/oct./2017 13:14
par RSBasic
Bonjour,

Deepl.com est très bon et est meilleur que Google Translator.
Ma WinAPI Library est disponible en quatre langues et les textes ont été traduits automatiquement avec Google Translator.
Parce que Deepl.com est bon, je traduis les textes avec Deepl.com plus tard.

Sur la page suivante il y a une solution avec PowerShell pour envoyer le texte au site web via JSON: https://psvmware.wordpress.com/2017/09/ ... owershell/
J'ai changé le code pour que vous puissiez passer les paramètres à la fonction (je suis un débutant en Powershell.):

Code : Tout sélectionner

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]
Voici le PB code pour appeler ce ps1 fichier à traduire:

Code : Tout sélectionner

EnableExplicit

Define Program

Define PSFile$ = "C:\...\File.ps1"
Define Sentence$ = "Bonjour monde"
Define FromLang$ = "FR"
Define ToLang$ = "EN"

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;Si vous voulez lire la première ligne
    EndIf
  Wend
  
  CloseProgram(Program)
EndIf
Si quelqu'un veut traduire le code PowerShell en code PB, veuillez poster ici. :)

Re: Deepl.com - Traduction automatique (Windows)

Publié : jeu. 26/oct./2017 16:02
par Shadow
Grâce à un membre d'ici, Falsam je crois, je l'es découvert et effectivement il est assez bluffant !

Re: Deepl.com - Traduction automatique (Windows)

Publié : jeu. 26/oct./2017 16:28
par Marc56
Pour les spécialistes du format JSON, une autre documentation pour utiliser l'API Deepl

:arrow: Source: https://stackoverflow.com/questions/459 ... slate-text
(Je pense qu'il faut remplacer TEXT_TO_TRANSLATE par son texte.)

:!: Comme c'est une API non documentée et non-officielle, elle peut disparaitre à tout moment.

(pas testé. J'ai un peu de mal avec ce format, il faut que je retrouve le tuto sur le forum)

:wink:

Re: Deepl.com - Traduction automatique (Windows)

Publié : ven. 27/oct./2017 18:46
par Kwai chang caine
Moi j'ai plusieurs problèmes avec ce code. W10 X64 V5.60
Les guillemets Chr(34) ne fonctionnent pas, il a fallu les remplacer par des quotes Chr(39)

Code : Tout sélectionner

Program = RunProgram("cmd.exe", "/c PowerShell.exe -Command " + "'" + PSFile$ + "'" + " '" + Sentence$ + "' '" + FromLang$ + "' '" + ToLang$ + "'", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
Et j'ai apparemment encore un problème d'UNICODE :|
Debug a écrit :Au caract�re Ligne:1 : 59
+ ... pL traduction automatique [RsBasic]\File.ps1' 'Bonjour monde' 'FR' 'E ...
+ ~~~~~~~~~~~~~~~
Jeton inattendu ��'Bonjour monde'�� dans l'expression ou l'instruction.
Au caract�re Ligne:1 : 75
+ ... traduction automatique [RsBasic]\File.ps1' 'Bonjour monde' 'FR' 'EN'
+ ~~~~
Jeton inattendu ��'FR'�� dans l'expression ou l'instruction.
Au caract�re Ligne:1 : 80
+ ... traduction automatique [RsBasic]\File.ps1' 'Bonjour monde' 'FR' 'EN'
+ ~~~~
Jeton inattendu ��'EN'�� dans l'expression ou l'instruction.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken