cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

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