Hi,
This is a practical, useful feature,
In a dialog, if the role of a control is STATICTEXT or CHECKBUTTON or PUSHBUTTON , I need to translate it
In order to make the translation faster, I thought of the following method:
1.get all the controls text that needs to be translated
2.Merge all text into one line, the delimiter is | , Replace some symbols like , : Like this below
hello world | hello friend | Father | Mother | my city | your country
3.Use Google Translate the line text, and re-split the string, delimiter is |
4.Set the translated text to the matching control
5.When I press the hotkey Ctrl+Q again, the controls text returns to its original
In the QM code below, I've only done part of it, I can only translate the text of one control at a time
My level of programming is not very good, some are not done
this is a very comprehensive example
Thanks for any advice and help
david
Macro Tran
This is a practical, useful feature,
In a dialog, if the role of a control is STATICTEXT or CHECKBUTTON or PUSHBUTTON , I need to translate it
In order to make the translation faster, I thought of the following method:
1.get all the controls text that needs to be translated
2.Merge all text into one line, the delimiter is | , Replace some symbols like , : Like this below
hello world | hello friend | Father | Mother | my city | your country
3.Use Google Translate the line text, and re-split the string, delimiter is |
4.Set the translated text to the matching control
5.When I press the hotkey Ctrl+Q again, the controls text returns to its original
In the QM code below, I've only done part of it, I can only translate the text of one control at a time
My level of programming is not very good, some are not done
this is a very comprehensive example
Thanks for any advice and help
david
Macro Tran
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Press Ctrl+Q translate controls text" "4"
;3 Button 0x54032000 0x0 32 44 48 14 "Father"
;4 Button 0x54032000 0x0 144 44 48 14 "Mother"
;5 Static 0x54000000 0x0 40 16 48 13 "hello,world"
;6 Static 0x54000000 0x0 144 16 48 13 "hello: friend"
;7 Button 0x54012003 0x0 32 72 48 10 "my city"
;8 Button 0x54012003 0x0 144 72 64 10 "your country"
;9 Edit 0x54030080 0x200 8 96 72 12 ""
;10 Edit 0x54030080 0x200 144 96 72 12 ""
;1 Button 0x54030001 0x4 48 116 48 14 "OK"
;2 Button 0x54030000 0x4 120 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""
str controls = "7 8 9 10"
str c7my c8you e9 e10
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,DT_SetAccelerators(hDlg "401 Cq")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 401 ;;Ctrl+Q
,;Todo_1: Gets all the specific role controls text (STATICTEXT or CHECKBUTTON or PUSHBUTTON)
,
,;Todo_2: Merge all text into one line, the delimiter is | , Replace some symbols like , :
,
,;Todo_3: Use Google Translate text, and re-split the string, delimiter is | see below #sub tran
,
,;Todo_4: Set the translated text to the matching control
,;Todo_5: When I press the hotkey Ctrl+Q again, the controls text returns to its original
,_s.getwintext(id(5 hDlg))
,_s.replacerx(",|:" " ") ;;Replace , : with spaces
,_s=sub.tran(_s) ;;Translate control text
,_s.setwintext(id(5 hDlg))
ret 1
#sub tran
function'str str's
;Todo_3: change the following Powershell code to QM code
;sl=en -> Set the source language
;tl=zh-CN -> Set the target language
_s=
F
;function tran
;{{
;,$data = @('', '')
;,$objRet = Invoke-WebRequest "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=zh-CN&dt=t&q=$args"
;,$data[0] = $objRet.Content
;,$objJson = ConvertFrom-Json $data[0]
;,$objJson[0][0][0]
;}
;tran "{s}"
PsCmd2 _s "" _s
ret _s.trim