cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
lala
Level VII

How does JSL call google's web translation results?

For example, how do I translate the specified English content into Chinese?
This is the result of a GPT3.5 query and does not work.

Thanks!

url = "https://translate.google.com";
sourceText = "Hello, world!";
targetLanguage = "zh-CN";  // Chinese Simplified

// Build the HTTP request
postData = "sl=en&tl=" || urlEncode(targetLanguage) || "&text=" || urlEncode(sourceText);
headers = Associative Array("Content-Type", "application/x-www-form-urlencoded", "User-Agent", "Mozilla/5.0");

httpReq = New HTTP Request(
    url,
    "POST",
    headers,
    postData
);

// Send the HTTP request and retrieve the response
httpReq.Send();
response = httpReq.ResponseBody();

// Extract the translation
startPos = Pos(response, "<span title=\"") + Length("<span title=\"");
endPos = Pos(response, "\">", startPos);
translation = Substr(response, startPos, endPos - startPos);

// Display the translation result
Show("Source Text: " || sourceText);
Show("Translation: " || translation);
1 REPLY 1
jthi
Super User

Re: How does JSL call google's web translation results?

There are many many incorrect functions used in your example. I would first use scripting index to fix those and then get back here if needed.

-Jarmo