Nun ist aber gut.
Code: Alles auswählen
Structure _JSON_OBJ4_
num_symbols.i
totalLogProb.i
score.i
postprocessed_sentence.s
EndStructure
Structure _JSON_OBJ3_
timeAfterPreprocessing.i
timeReceivedFromEndpoint.i
List beams._JSON_OBJ4_()
total_time_endpoint.i
timeSentToEndpoint.i
EndStructure
Structure _JSON_OBJ2_
source_lang.s
target_lang.s
List translations._JSON_OBJ3_()
ource_lang_is_confident.i
EndStructure
Structure _JSON_OBJ_
jsonrpc.s
id.i
result._JSON_OBJ2_
EndStructure
Structure _JSON_SEND4_
List user_preferred_langs.s()
source_lang_user_selected.s
target_lang.s
EndStructure
Structure _JSON_SEND3_
kind.s
raw_en_sentence.s
EndStructure
Structure _JSON_SEND2_
List jobs._JSON_SEND3_()
lang._JSON_SEND4_
priority.i
EndStructure
Structure _JSON_SEND_
jsonprc.s
method.s
params._JSON_SEND2_
id.i
EndStructure
Procedure.s Translate(Sentence$, FromLang$, ToLang$)
Protected Program, s.s, Result.s
Protected CurlOptions.s
Protected R._JSON_OBJ_, SE._JSON_SEND_
Sentence$ = ReplaceString(Sentence$, #LF$, #ESC$)
AddElement(SE\params\jobs())
SE\jsonprc = "2.0"
SE\method = "LMT_handle_jobs"
SE\Params\jobs()\kind = "default"
SE\params\jobs()\raw_en_sentence = Sentence$
SE\params\lang\source_lang_user_selected = FromLang$
SE\params\lang\target_lang = ToLang$
SE\params\priority = -1
SE\id = 15
AddElement(SE\params\lang\user_preferred_langs()) : SE\params\lang\user_preferred_langs() = "DE"
AddElement(SE\params\lang\user_preferred_langs()) : SE\params\lang\user_preferred_langs() = "EN"
If CreateJSON(0)
InsertJSONStructure(JSONValue(0), @SE, _JSON_SEND_)
CurlOptions = ComposeJSON(0)
CurlOptions = ReplaceString(CurlOptions, #DQUOTE$, "\" + #DQUOTE$)
FreeJSON(0)
EndIf
Program = RunProgram(GetPathPart(ProgramFilename()) + "curl.exe", "-X POST --insecure -ss -d " + #DQUOTE$ + CurlOptions + #DQUOTE$ + " https://www.deepl.com/jsonrpc", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
If Program
While ProgramRunning(Program)
If AvailableProgramOutput(Program)
s = ReadProgramString(Program)
If ParseJSON(0, s)
ExtractJSONStructure(JSONValue(0), @R, _JSON_OBJ_)
FreeJSON(0)
If FirstElement(R\result\translations()) And FirstElement(R\result\translations()\beams())
Result = R\result\translations()\beams()\postprocessed_sentence
EndIf
EndIf
Break
EndIf
Wend
CloseProgram(Program)
EndIf
Result = ReplaceString(Result, #ESC$, #LF$)
ProcedureReturn Result
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
Debug Translate("pretty world", "EN", "DE")
CompilerEndIf
Mit dieser "Fehlerbeschreibung" kann dir sicherlich niemand helfen.
Eine Idee hätte ich:
Solange Du den Source nicht gespeichert hast (weil du es ja nur testen wolltest), wird PB die exe im TEMP-Verzeichnis anlegen und dort natürlich die curl.exe nicht finden.