View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Joe Nastasi Joe Nastasi is offline
external usenet poster
 
Posts: 5
Default Spreadsheet translation

Joel,

That would be GREAT and a huge help!! Assume foreign text is in Sheet1!A1
and I want to put translated result in Sheet2!A1. Here is the html for a
page that does what you request. Thanks in advance for your help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"

<head
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
<titleGoogle Translate API</title
</head

<body


<form name="f" id="f" action="#" onsubmit="translate(); return false;"

<textarea name="foreign_text" id="foreign_text" rows="4"
cols="60"</textarea
<br /
<br /

<input type="submit" id="submit_button" value="Translate into English"
onfocus="this.blur();" /
<br /
<br /

<textarea name="translation" id="translation" rows="4" cols="60"
onfocus="this.select();" readonly="true"</textarea</form
<br /

<script type="text/javascript" src="http://www.google.com/jsapi"</script
<script type="text/javascript"
google.load("language", "1");
function translate() {var
originaltext=document.forms["f"].foreign_text.value;
google.language.translate(originaltext, "", "en", function(result) {
document.forms["f"].translation.value = (result.error)?("Error:
"+result.error.message):result.translation; }); }
</script

</body
</html




"joel" wrote in message
...
If you can setup a webpage with two tex boxes. One box for input and one
box
for output and a submit button to perform translation. give each box and
button a unique ID. I can write the code to move the data from the
spreadsheet to the inbox and take the translation from the translation box
to
the spreadsheet. this is real simple.

"Joe Nastasi" wrote:

No, the API is not a Win32 dll. It is a web service hosted by google.
You
send an XML message containing your API request in javascript to the
google
server, and it sends back a response also in XML.

Thanks for the code example... I think it could work, but I would have to
read up on the Internet Explorer DOM to figure out how insert the API
request as <script type="text/javascript" into the html of the web page
and
how to read the response.

Information of the google translate API can be found he
http://code.google.com/apis/ajaxlanguage/

"joel" wrote in message
...
I guess the API is a win32 dll. Here is some interesting code. I don't
know
how to get to the google API. Do you have a URL?


Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long


Sub GetID()
Set modObjIE = CreateObject("InternetExplorer.Application")
modObjIE.Visible = True
Handle = modObjIE.hwnd


WindowName = "Windows Internet Explorer"
lngProcessID = FindWindow(vbNullString, WindowName)

MsgBox "Handle = " & Handle & ", ID = " & lngProcessID
End Sub

"Joe Nastasi" wrote:

I have a spreadsheet of a foreign company's financial statements. I
want
to
translate all text into English and keep numbers as is. I know Google
has
an AJAX/javascript API that can do the translation... Can anyone think
of
a
way to automate the task with VBA... Is it possible to write a
function
that
would instantiate a WebBrowser control within VBA and use it to invoke
the
Google API to translate a single cell. Then I could write a procedure
to
loop through all cell in the spreadsheet, check if they are text and
if
so
call my function to translate the cell.

Thanks in advance for any advice.

Joe