| View previous topic :: View next topic |
| Author |
Message |
covar General User

Joined: 17 Feb 2007 Posts: 25
|
Posted: Mon Sep 05, 2011 10:30 pm Post subject: Google translator for OpenOffice/LibreOffice |
|
|
See my code (translate EN->RU):
| Code: | Sub google_translator_en_ru
Dim o As Object
oDoc=ThisComponent
oSheet=oDoc.CurrentController.getActiveSheet()
'Source text
oCell1 = oDoc.CurrentSelection
ncol=oCell1.CellAddress.Column
nrow=oCell1.cellAddress.Row
TextEN=oCell1.getString()
'ActiveX "InternetExplorer"
o=CreateObject("InternetExplorer.Application")
'Google Translator
o.Navigate2("http://translate.google.com/?langpair=en|ru&text=" & TextEN)
WHILE o.ReadyState <> 4
wait 10
WEND
'received text
webText=o.Document.body.InnerText
aStr1=Split(webText, Chr(10))
l1 = LBound(aStr1)
u1 = UBound(aStr1)
'looking translated text
'''''''''''''''''''''''''''''''''''''''''''''''''''
ns=19
spl="***"
aStr0 = aStr1(ns)
aStr0 = Replace(aStr0, ".", "." & spl)
aStr0 = Replace(aStr0, "!", "!" & spl)
aStr0 = Replace(aStr0, "?", "?" & spl)
aStr2=Split(aStr0, spl)
l2 = LBound(aStr2)
u2 = UBound(aStr2)
aStr=""
For k=l2 To (u2/2)-1
aStr=aStr & aStr2(k)
Next k
'''''''''''''''''''''''''''''''''''''''''''''''''''
oCell20=oSheet.getCellByposition(ncol+1,nrow)
oCell20.setString(aStr)
End Sub |
In Russian (screenshot and example):
http://libreoffice.3nx.ru/viewtopic.php?p=32#32
Moderation probe1: moved to CODE SNIPPETS section, although untested |
|
| Back to top |
|
 |
fredrikl General User

Joined: 14 Feb 2010 Posts: 15 Location: Stockholm, Sweden
|
Posted: Sun Apr 21, 2013 12:36 pm Post subject: Internet Explorer 9+ |
|
|
Nice code covar. I did not know this was possible.
I got most of your your code to work on Internet Explorer 8. Unfortunately it looks like ".InnerText" at the line:
| Code: | | webText=o.Document.body.InnerText |
does not work on Internet Explorer 10. Tried to find a solution to it on the Internet and tested a lot of different things but nothing worked. ".InnerText" seems to be a problem for many other persons not related to OpenOffice but running Internet Explorer 9+.
If you had this problem and solved it please post your solution and you will make me happy.
Thanks, _________________ Fredrik
Portable OpenOffice.org 3.2, Windows 7 64-bit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|