Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Translate the specific controls in the dialog one by one
#4
@Kevin

Hello, I put the Translate Control function, saved as a separate function (Tran_Ctrls) It assigns a hotkey Ctrl+Q

This way I can translate controls from other windows, but a lot of times it doesn't work,

is there a way to make the functions more generic? Thanks in advance

For example, I want to translate controls inside the custom dialog
[Image: a.png]

Function Tran_Ctrls
Trigger Cq     Help - how to add the trigger to the macro
Code:
Copy      Help
int h = win

int tn
ARRAY(str) translate original
ARRAY(int) a

tn=!tn
if(translate.len =0)
,ARRAY(str) roles="STATICTEXT[]PUSHBUTTON[]CHECKBUTTON[]RADIOBUTTON[]LISTITEM[]CLIENT"
,Acc a1.Find(h "DIALOG") ;;WINDOW
,ARRAY(Acc) ac
,a1.GetChildObjects(ac 1)
,for _i 0 ac.len
,,Acc& r1=ac[_i]
,,str role name
,,r1.Role(role); name=r1.Name
,,for int'i 0 roles.len
,,,if(!StrCompare(role roles[i]))
,,,,a[]=r1.Hwnd
,,,,original[]=name
,,,,name.replacerx(",|:" " ") ;;Replace , : with spaces
,,,,if _i !=ac.len-1
,,,,,name+ " | "
,,,,_s+name
,sub.GetTranslation(_s "en" "zh-CN" &translate) ;;Translate control text
,_s=translate
,out _s
int ii=0
for i 0 a.len
,if(tn)
,,translate[ii].replacerx("\|" "");err
,,translate[ii].rtrim;err
,,translate[ii].setwintext(a[i]);err
,else
,,original[ii].setwintext(a[i]);err
,ii+1

#sub GetTranslation
function ~sourceText ~sourceLang ~targetLang ARRAY(str)&tl

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
IXml x=JsonToXml(s)
IXmlNode r=x.RootElement
ARRAY(IXmlNode) a; r.Path("item/item/item[@type='string']" a 1)
for(int'i 0 a.len)
,,if(!(i&1))
,,,tl[]=a[i].Value

I found a more general way to locate:
Acc a.Find(w "RADIOBUTTON" "" "class=Button" 0x1004 1 1)     -> Positioning of the first button
Acc a.Find(w "RADIOBUTTON" "" "class=Button" 0x1004 1 2)     -> Positioning of the second button

If there is no third button, with the method above, an error will occur

Acc a1.Find(w1 "CHECKBUTTON" "" "class=Button" 0x1004 1 1)   -> Positioning of the first checkbutton
If there is no second checkbutton, with the method above, an error will occur

...... Other control positioning is the same logic 

But  I don't know how to modify the code above 
Huh

@Gintaras

Currently, learning QM and Uiscripter, my biggest obstacle is poor English proficiency, at the same time, the software interface is not localized, 

Can you use Uiscripter to create an assistant with a translation UI interface similar to the one above? Thanks in advance Heart

With an assistant similar to the above, it is convenient for more people to use and learn QM and Uiscripter


Messages In This Thread
RE: Translate the specific controls in the dialog one by one - by Davider - 07-23-2022, 12:28 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)