cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
lala
Level IX

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

Recommended Articles