Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Embed Google Translate Website, Prompt Website Security Issue
#1
My English reading ability is not very good, so when using QM help, I often use Google Translate. Now I want to make a small tool to translate the current help page. 

However, when I embed a Google Translate URL in a child window, it prompts for a website security certificate and cannot display Google Translate pages. How can I disable security certificate prompting?   Huh   Just discovered that Microsoft Online Translator can open URLs Idea

Custom right-click menu with two options

1.The first option is the function that will be implemented because my programming level is not good and no code has been added yet

2.The second option is to open Google Translate directly in a child window

I hope someone can help me improve this tool, let more people use this tool, translate help files to learn QM, Thanks in advance  Smile


Macro trans help
Code:
Copy      Help
typelib ShockwaveFlashObjects {D27CDB6B-AE6D-11CF-96B8-444553540000} 1.0
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 900 432 "Dialog"
;4 ActiveX 0x54030000 0x0 0 0 900 432 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "4"
str ax4SHD
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SetTimer hDlg 1 100 0
,SHDocVw.WebBrowser we4
,we4._getcontrol(id(4 hDlg))
,we4._setevents("sub.we4")
,we4.Navigate("http://www.quickmacros.com/help/")
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(4 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 2 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;OutWinMsg message wParam lParam ;;uncomment to see received messages

sel message
,case WM_RBUTTONDOWN
,str s=
,;1 Translate this page use google
,;2 Google Translate Website
,;-    
,;3 Translate this page use Microsoft
,;4 Microsoft  Translate Website    
,MenuPopup x.AddItems(s)
,int i=x.Show
,sel i
,,case 1
,,_s=
,,F
,,;Copy the current page or Copy selected paragraph code
,,;then open the Google Translate in subwindow
,,;then paste the page content or selected paragraph code on the left side of the sub window
,,mes _s
,,case 2
,,sub.Dialog2(hwnd "https://translate.google.com/")
,,case 3
,,mes "Translate this page use Microsoft"
,,case 4
,,sub.Dialog2(hwnd "https://cn.bing.com/translator/")
,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass)
,
,;case ...

ret R

#sub we4_NewWindow3
function IDispatch&ppDisp @&Cancel dwFlags BSTR'bstrUrlContext BSTR'bstrUrl SHDocVw.IWebBrowser2'we3

int hDlg2=sub.Dialog2
SHDocVw.WebBrowser d2_we3._getcontrol(id(3 hDlg2))
ppDisp=d2_we3



#sub Dialog2
function# [hwndOwner] [~url]

str dd=
;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 900 432 "Dialog2"
;3 ActiveX 0x54030000 0x0 0 0 900 432 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040701 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!empty(url))
,ax3SHD=url
ret ShowDialog(dd &sub.DlgProc2 &controls hwndOwner 1) ;;modeless dialog


#sub DlgProc2
function# hDlg message wParam lParam
int- t_hdlg

sel message
,case WM_INITDIALOG
,SHDocVw.WebBrowser we3
,we3._getcontrol(id(3 hDlg))
,we3._setevents("sub.we3")
,t_hdlg=hDlg
,DT_SetAutoSizeControls hDlg "3s"
,SetTimer hDlg 1 100 0
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(3 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 2 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_CLOSE
,DT_Ok(hDlg)
ret
;messages2
sel wParam
,case IDOK
,ifk(Y)
,,key Y           ;; Enter
,,ret 0
,case IDCANCEL
,ret 0

ret 1

#sub we3_WindowClosing
function @IsChildWindow @&Cancel ;;SHDocVw.IWebBrowser2'we3

Cancel=1
int- t_hdlg
clo t_hdlg
#2
maybe security issue will be fixed using this
http://www.quickmacros.com/forum/showthr...9#pid31339
if not will need to change settings in internet explorer

translating online help page presents some challenges as the web page is in frames and the translators dont seem to like that
but this might work for you
change this line
we4.Navigate("http://www.quickmacros.com/help/")
to
we4.Navigate("http://www.microsofttranslator.com/bv.aspx?from=&to=zh-CHT&a=http%3A%2F%2Fwww.quickmacros.com%2Fhelp%2Fleft.htm")
use backspace key once you click a link to return to main page
or
we4.Navigate("https://translate.google.com/translate?hl=en&sl=en&tl=zh-TW&u=http%3A%2F%2Fwww.quickmacros.com%2Fhelp%2Fleft.htm")
a little more work to open links need to click the link in the popup tooltip

translation is set from english to traditional chinese .Adjust to preferred language as needed

also check out 
http://www.quickmacros.com/forum/showthr...9#pid29109
and 
http://www.quickmacros.com/forum/showthr...5#pid29115
#3
Thanks for your reminder, I tested can't work  Huh

Macro test
Code:
Copy      Help
lpstr ssourceText=
;hell, world

out GoogleTranslator(ssourceText "zh-CN")

Function GoogleTranslator
Code:
Copy      Help
;/
function'str str'sourceText str'targetLang [str'sourceLang]

lpstr PatternLanguageCode="^(af|ga|sq|it|ar|ja|az|kn|eu|ko|bn|la|be|lv|bg|lt|ca|mk|zh\-CN|ms|zh\-TW|mt|hr|no|cs|fa|da|pl|nl|pt|en|ro|eo|ru|et|sr|tl|sk|fi|sl|fr|es|gl|sw|ka|sv|de|ta|el|te|gu|th|ht|tr|iw|uk|hi|ur|hu|vi|is|cy|id|yi)$"

if findrx(targetLang PatternLanguageCode)<0
,end F"targetLang: '{targetLang}' Language Code not supported"

if empty(sourceLang)
,sourceLang="auto"

if sourceLang<>"auto" and findrx(sourceLang PatternLanguageCode)<0
,end F"sourceLang: '{sourceLang}' Language Code not supported"

sourceText.escape(11)

str s

IntGetFile F"https://translate.googleapis.com/translate_a/single?client=gtx&sl={sourceLang}&tl={targetLang}&dt=t&q={sourceText}" s

int i=find(s "]],,''")
if(i>0) s.get(s 2 i) ;;phrase, else word

s.findreplace("\''" "[1]")
s.replacerx("\[''([^'']+)'',''[^'']+'',,,\d\](,|\]$)" "$1")
s.findreplace("[1]" "''")
s.findreplace("\r" "[13]")
s.findreplace("\n" "[10]")
s.findreplace("\t" "[9]")
s.findreplace("\\" "\")
s.findreplace("\u003c" "<")
s.findreplace("\u003e" ">")
if(!_unicode) s.ConvertEncoding(CP_UTF8 CP_ACP)

ret s
#4
translate function working for me  so dont know the problem


Maybe something like this will work
Function WebTranslator
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x10CF0A48 0x100 0 0 900 432 "Web Translator"
;3 ActiveX 0x54000000 0x4 12 20 236 154 "SHDocVw.WebBrowser"
;4 Button 0x54032001 0x4 0 0 48 14 "Back"
;5 Button 0x54032000 0x4 48 0 48 14 "Forward"
;6 Button 0x54032000 0x0 96 0 48 14 "Stop"
;7 Button 0x54032000 0x0 144 0 48 14 "Refresh"
;8 Button 0x54032000 0x0 192 0 48 14 "Home"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

str controls = "3"
str ax3SHD
WebBrowserControlDisableIE7Emulation
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SHDocVw.WebBrowser we3
,we3._getcontrol(id(3 hDlg))
,we3.Silent=TRUE ;;prevent script error messages
,;we3.Navigate("http://www.microsofttranslator.com/bv.aspx?from=&to=zh-CHT&a=http%3A%2F%2Fwww.quickmacros.com%2Fhelp%2Fleft.htm");;Chinese Traditional
,we3.Navigate("http://www.microsofttranslator.com/bv.aspx?from=&to=zh-CHS&a=http%3A%2F%2Fwww.quickmacros.com%2Fhelp%2Fleft.htm") ;;Chinese Simplified
,case WM_SIZE
,RECT r; DpiGetWindowRect(hDlg &r)
,MoveWindow id(3 hDlg) 0 30 r.right r.bottom-30 1
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case [4,5,6,7,8]
,err-
,we3._getcontrol(id(3 hDlg))
,sel wParam
,,case 4 we3.GoBack
,,case 5 we3.GoForward
,,case 6 we3.Stop
,,case 7 we3.Refresh
,,case 8 we3.GoHome
,err+    
,case IDOK
,case IDCANCEL
ret 1
   
#5
Sometimes, I just want to open QM to help translate the selected paragraph, but the following code does not work, can you test it for me? thanks

In China, the URL https://translate.google.com cannot be used but only the URL https://translate.google.cn/

But I can't translate it after I changed com to cn

Function Translator
Trigger CF12     Help - how to add the trigger to the macro
Code:
Copy      Help
;/
str selected_text.getsel

int h
GetWorkArea 0 0 0 h

int w=win

RECT r
scan F"color:{GetSysColor(COLOR_HIGHLIGHT)}" w r 2|16

int y=r.top+100

if y+100>h
,y=r.top-100

OnScreenDisplay "Wait a second..." 10 r.left y "" 12 0xff0000 1|4|16 "my-tooltip" 0xc0ffff

str translated_text=GoogleTranslator(selected_text "zh-CN")

OnScreenDisplay translated_text 0 r.left y "" 12 0xff0000 1|4|16 "my-tooltip" 0xc0ffff

err+ OnScreenDisplay "Error"
#6
the GoogleTranslator   function uses  Google translate api and that api is not available in china so i'm sorry you wont be able to make it work.

google does offer a free translate app for android and ios that can be used.


Forum Jump:


Users browsing this thread: 1 Guest(s)