Posts: 1,271
Threads: 399
Joined: Mar 2003
i try to use a webservice for translating a word,
the webservice url is :
Translate
i can send, but the result is ever 0.
typelib MSXML2 {F5078F18-C551-11D3-89B9-0000F81FE221} 4.0
MSXML2.XMLHTTP a._create
str xml =
;<?xml version="1.0" encoding="utf-8"?>
;<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
;;<soap:Body>
;;;;<Translate xmlns="http://www.webservicex.net">
;;;;;;<LanguageMode>EnglishTOGerman</LanguageMode>
;;;;;;<Text>string</Text>
;;;;</Translate>
;;</soap:Body>
;</soap:Envelope>
a.open("Post","http://www.webservicex.net/Translate/TranslateService.asmx",0)
a.setRequestHeader("Content-Type","text/xml")
a.send(xml)
MSXML2.FreeThreadedDOMDocument b._create
b.async
str r = a.responseXML = "xml"
;out b.loadXML(r)
out a.responseXML
using webservices would be very helpful:
Google Web APIs - Home
www.xmethods.net
thanks
Posts: 11,908
Threads: 138
Joined: Dec 2002
I don't say I understand here something, but I would try the following:
MSXML2.DOMDocument doc=a.responseXML
out doc.xml
Posts: 1,271
Threads: 399
Joined: Mar 2003
no
i use a similar script to post content to my website,
so i know that sending is working.
but i can't get the response into qm.
Posts: 11,908
Threads: 138
Joined: Dec 2002
This code really works.
2010.6.16: now this service does not work.
Look here: Translate text using Google
typelib MSXML2 {F5078F18-C551-11D3-89B9-0000F81FE221} 4.0
MSXML2.XMLHTTP a._create
str xml =
;<?xml version="1.0" encoding="utf-8"?>
;<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
;;<soap:Body>
;;;;<Translate xmlns="http://www.webservicex.net">
;;;;;;<LanguageMode>EnglishTOGerman</LanguageMode>
;;;;;;<Text>one</Text>
;;;;</Translate>
;;</soap:Body>
;</soap:Envelope>
a.open("POST","http://www.webservicex.net/TranslateService.asmx",0)
a.setRequestHeader("Content-Type","text/xml")
a.setRequestHeader("SOAPAction" "http://www.webservicex.net/Translate")
a.send(xml)
MSXML2.DOMDocument doc=a.responseXML
out doc.xml
Output:
<?xml version="1.0"?>
<soap:Envelope xmlns oap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><TranslateResponse xmlns="http://www.webservicex.net"><TranslateResult>ein</TranslateResult></TranslateResponse></soap:Body></soap:Envelope>
Posts: 1,271
Threads: 399
Joined: Mar 2003
wow, cool !!!
now i only have to write a shortliner to extract <TranslateResult>ein</TranslateResult>.
on [win T] i send a text selection from anywhere in windows to the webservice and a qm dialog shows the result.
no need to use an extra browser tab/window anymore.
Posts: 11,908
Threads: 138
Joined: Dec 2002
Posts: 1,271
Threads: 399
Joined: Mar 2003
thanks again.
is there any way to insert a qm variable directly in multiline code like:
str xml =
;<?xml version="1.0" encoding="utf-8"?>
;<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
;<soap:Body>
;<Translate xmlns="http://www.webservicex.net">
;<LanguageMode>EnglishTOGerman</LanguageMode>
;<Text>$$selection$$</Text>
;</Translate>
;</soap:Body>
;</soap:Envelope>
Posts: 11,908
Threads: 138
Joined: Dec 2002
No.
xml.findreplace("$$selection$$" s)
Posts: 1,271
Threads: 399
Joined: Mar 2003
the translation to german is not perfect, maybe there is a better webservice
for translation.
str s.getsel(0)
typelib MSXML2 {F5078F18-C551-11D3-89B9-0000F81FE221} 4.0
MSXML2.XMLHTTP a._create
str xml =
;<?xml version="1.0" encoding="utf-8"?>
;<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
;<soap:Body>
;<Translate xmlns="http://www.webservicex.net">
;<LanguageMode>EnglishTOGerman</LanguageMode>
;<Text>$$text$$</Text>
;</Translate>
;</soap:Body>
;</soap:Envelope>
xml.findreplace("$$text$$" s)
a.open("POST","http://www.webservicex.net/TranslateService.asmx",0)
a.setRequestHeader("Content-Type","text/xml")
a.setRequestHeader("SOAPAction" "http://www.webservicex.net/Translate")
a.send(xml)
MSXML2.DOMDocument doc=a.responseXML
;BEGIN DIALOG
;0 "" 0x10480A44 0x100 0 0 195 78 "translation result"
;1 Button 0x54030001 0x4 4 26 48 14 "copy"
;3 Edit 0x54030080 0x200 4 6 178 18 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010505 "" ""
str controls = "3"
str e3 = doc.text
if(!ShowDialog("translate2" 0 &controls)) ret
;to be continued
Posts: 1,271
Threads: 399
Joined: Mar 2003
how do i place my dialog near mouse ?
how do i open the dialog without DlgFrame/Caption ?
left click on result edit field = copy
right click = close
Posts: 11,908
Threads: 138
Joined: Dec 2002
1. Set DS_CENTERMOUSE style.
2. Caption is added even when WS_CAPTION is not selected. Use SetWinStyle in WM_INITDIALOG.
3,4. Use WM_SETCURSOR message.
Of course, you need a separate function for dialog procedure.
;\Dialog_Editor
function# hDlg message wParam lParam
;BEGIN DIALOG
;0 "" 0x10081042 0x8 0 0 109 28 ""
;3 Edit 0x54030080 0x204 6 8 96 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010505 "" ""
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam)
,SetWinStyle hDlg 0 8
,ret 1
,case WM_SETCURSOR
,sel(lParam>>16)
,,case WM_LBUTTONDOWN _s.getwintext(id(3 hDlg)); _s.setclip
,,case WM_RBUTTONDOWN EnableWindow id(3 hDlg) 0
,,case WM_RBUTTONUP DT_Cancel hDlg
,case WM_DESTROY DT_DeleteData(hDlg)
Posts: 1,271
Threads: 399
Joined: Mar 2003
i still have the titlebar in the dialog ?
Posts: 11,908
Threads: 138
Joined: Dec 2002
Try SetWinStyle with flag 8 (see the updated code above).
Posts: 1,271
Threads: 399
Joined: Mar 2003
thanks, i had to restart qm. now its working.
Posts: 858
Threads: 196
Joined: Apr 2005
Is possible to do this with google?
Posts: 11,908
Threads: 138
Joined: Dec 2002
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 11,908
Threads: 138
Joined: Dec 2002
GoogleTranslate should give correct text.
Is your QM running in Unicode mode? Look in Options.
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 11,908
Threads: 138
Joined: Dec 2002
I updated the code. Now works with bigger text (although still limited), and works better in non-Unicode mode.
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 858
Threads: 196
Joined: Apr 2005
When I try:
Macro Macro4
str t r
t=GoogleTranslate("España" "en" "" 0 r)
if(t) out t
else out r
output: Espa?a -------------> Spain
Posts: 11,908
Threads: 138
Joined: Dec 2002
Let QM work in Unicode mode and will be OK.
Posts: 858
Threads: 196
Joined: Apr 2005
Posts: 11,908
Threads: 138
Joined: Dec 2002
Now I updated the function. Works better if input is not UTF-8.
|