last day (15 days later) » 

05:21
6
A: How to translate a list of English words in to other language using online translation service with mathematica?

RashidSince the Google Translate API requires authentication, a simple work around is to deploy as a web app a Google Apps Script that uses Google's LanguageApp, and then call that using URLExecute[]. To setup the Apps Script, go to script.google.com and create a new script with the following doGet f...

Hi, Rashid. Your approach seems great. I have followed your step. But I got this error: "TypeError: Cannot read property "0" from undefined.(行 \ 3、ファイル「Code」、プロジェクト「doGet」)"
@matheorem, thanks for the comment. Sorry about that. There was an inconsistency between the parameters in onlineTrans and in line 3 of the Google script. Please change the last onlineTran parameter to be "language" instead of "languagecode". I will edit right now. (Sorry, I must have introduced this while tying to cleanup the code.)
Oops, Now I got this "ReferenceError: "texts" is not defined.(行 6、ファイル「Code」、プロジェクト「doGet」)"
Sorry, @matheorem , I really botched this with my late edits to variable names. There is a typo now on lines 6 and 7 of the script, "texts" should be "textlist". Once you correct, you will need to "deploy again" and select "new" under the version options. (PS -The URL won't change, so you can leave the Mathematica code alone. ) will edit to correct now --learning my lesson that I should retest from scratch when posting edited code.
Thank you so much. I actually corrected "texts" to "textlist" before, however I selected the wrong version. I selected "1"... Anyway, there was another typo in your onlineTran, I corrected it now.
05:21
Thanks @matheorem for correcting onlineTran. I also edited to add an information about how to redeploy Apps Script, which I have to do all the time while debugging.
Rashid, do you know why the translated result is not in the source html page? I thought every thing should be in the source page. I am not familiar with the web things.
Sorry @matheorem, I am not a web expert myself, so I am not sure I understand your question. What source html page do you mean? (As far as I understand we are returning a plaintext answer with ContentService.createTextOutput. You may be able to do more with HtmlService.createHtmlOutput. These are the two options for Apps Script web apps)
I mean in browser you can look at the source code of the web page. Source page I mean something describe here w3schools.com/html
I would be glad to try and help. What is the URL of the source page you are looking at? Is it the URL of your deployed web app ( something like: "https://script.google.com/macros/s/alphaNumericSeq/exec")?
I only get errors when I try the Web App URL or the URL plus parameters in Chrome...
In Mathematica ... you might look at URLFetch[webAppURL<>"?"<>URLQueryEncode[{"textlist" -> "hello worlds","language" -> "fr"}], "Headers"] ...This shows me that I have only "text/plain" content being returned
05:36
@Rashid I mean for example this translation page translate.google.com/#en/zh-CN/nobel
Thanks @matheorem, let me take a look... Using the "inspect" elements feature in Chrome, it seems that translated text is in "result_box.short_text"
05:58
Sorry, I don't think I can be of much help. I tried looking at the html source in Mathematica with URLFetch["https://translate.google.com/#en/zh-CN/nobel"] where its easier to do StringCases pattern searches...but it looks like that site is also calling a script that populates that result_box element.
06:23
@Rashid sorry for late reply. So google translate call an external script, that is why we can't see the result in the source html, am I right?
 
7 hours later…
13:52
@matheorem yes, I think that is right. I believe this source is running an external script that returns the translation in the result_box element.
14:28
@Rashid That makes sense. Thank you very much, Rashid : )

last day (15 days later) »