Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
webservice example ? (translate text)
#1
i try to use a webservice for translating a word,
the webservice url is :
Translate

i can send, but the result is ever 0.

Code:
Copy      Help
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
pi
#2
I don't say I understand here something, but I would try the following:

Code:
Copy      Help
MSXML2.DOMDocument doc=a.responseXML
out doc.xml
#3
no Sad
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.
pi
#4
This code really works.

2010.6.16: now this service does not work.
Look here: Translate text using Google

Code:
Copy      Help
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 xmlnsConfusedoap="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>
#5
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.
pi
#6
out doc.text

Output:
ein
#7
thanks again.

is there any way to insert a qm variable directly in multiline code like:
Code:
Copy      Help
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>
pi
#8
No.

xml.findreplace("$$selection$$" s)
#9
the translation to german is not perfect, maybe there is a better webservice
for translation.

Code:
Copy      Help
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
pi
#10
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
pi
#11
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.

Code:
Copy      Help
;\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)
#12
i still have the titlebar in the dialog ?
pi
#13
Try SetWinStyle with flag 8 (see the updated code above).
#14
thanks, i had to restart qm. now its working.
pi
#15
Is possible to do this with google?
#16
Translate text using Google
#17
Thank you very much.
#18
How convert ó --> ó ?
#19
GoogleTranslate should give correct text.
Is your QM running in Unicode mode? Look in Options.
#20
Fixed. Thanks again.
#21
I updated the code. Now works with bigger text (although still limited), and works better in non-Unicode mode.
#22
Perfect.
#23
When I try:

Macro Macro4
Code:
Copy      Help
str t r
t=GoogleTranslate("España" "en" "" 0 r)
if(t) out t
else out r

output: Espa?a -------------> Spain
#24
Let QM work in Unicode mode and will be OK.
#25
Ok. Thanks.
#26
Now I updated the function. Works better if input is not UTF-8.


Forum Jump:


Users browsing this thread: 1 Guest(s)