try this out
Function DialogTranslateControls
also need this function
Function JsonToXml
Function DialogTranslateControls
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
,int- tn
,ARRAY(str)- translate original
,ARRAY(int)- a
,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
,tn=!tn
,if(translate.len =0)
,,ARRAY(str) roles="STATICTEXT[]PUSHBUTTON[]CHECKBUTTON"
,,Acc a1.Find(hDlg "DIALOG")
,,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
,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
ret 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
Function JsonToXml
;/
function'IXml $JSON [flags] ;;flags: 1 display XML text in QM output
;Converts JSON text to XML and returns IXml object.
;REMARKS
;On Windows XP SP2 and Vista must be installed .NET 3.5 or later. Older OS are not supported.
;EXAMPLE
;out
;str JSON=
;;{
;;;;;"hello": "world",
;;;;;"t": true ,
;;;;;"f": false,
;;;;;"n": null,
;;;;;"i": 123,
;;;;;"pi": 3.14,
;;;;;"Address": { "City": "New York", "State": "NY" },
;;;;;"a": [1, 2, 3, 4]
;;}
;IXml x=JsonToXml(JSON 1)
;IXmlNode r=x.RootElement
;;get simple
;out r.Child("hello").Value
;;get with XPath
;out r.Path("Address/State").Value
;;get array
;ARRAY(IXmlNode) a; r.Path("a/*" a)
;int i; for(i 0 a.len) out a[i].Value
opt noerrorshere 1
CsScript x.SetOptions("references=System.Xml;System.Runtime.Serialization;System.ServiceModel.Web")
x.AddCode("")
_s=x.Call("ToXml" JSON)
if(flags&1) out _s
IXml k._create
k.FromString(_s)
ret k
#ret
using System;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Xml;
using System.Xml.Linq;
public class Json
{
static public string ToXml(string JSON)
{
XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(JSON), new System.Xml.XmlDictionaryReaderQuotas());
return XElement.Load(reader).ToString();
}
}