Sub bnTrans_Click
Dim job As HttpJob
Dim transtr As String = edIn.Text
Dim jobname As String = "xlate"
Dim jobtag As String = "french"
job.Initialize(jobname, Me)
job.Tag = jobtag
' Use Google Free google API translate
Dim srclang As String = "en"
Dim dstlang As String = "hi"
Dim poststr As String = "https://Translate.googleapis.com/translate_a/single?client=gtx&sl=" & _
srclang & "&tl=" & dstlang & "&dt=t&q=" & transtr
job.Download(poststr)
lbOut.Text = ""
End Sub
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If (Job.Success = True) Then
Dim trans As String = Job.GetString
Log(trans)
'========Modified code to take only the first "Double quote Value"
Dim count=0, i=0 As Int
Do While i<2
If trans.SubString2(count, count+1)=$"""$ Then i=i+1
count=count+1
Loop
trans=trans.SubString2(0, count)
'========Modified code Over to take only the first "Double quote Value"
Log(trans)
Dim rlst As List = MyParser(trans)
Log(rlst.Size)
For Each sa() As String In rlst
If (sa.Length > 0) Then
If (lbOut.Text <> "") Then lbOut.Text = lbOut.Text & CRLF
lbOut.Text = lbOut.Text & sa(0)
End If
Next
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub MyParser(js As String) As List ' returns list of string arrays
Dim rlst As List
Dim sa1(), str As String
Dim p As Int
rlst.Initialize
sa1 = Regex.Split("]", js)
For Each s1 As String In sa1
p = s1.LastIndexOf("[")
If (p < 0) Then Continue
str = s1.SubString2(p + 1, s1.Length)
str = str.Replace(QUOTE, "")
Dim sa2() As String = Regex.Split(",", str)
rlst.Add(sa2)
Next
Return(rlst)
End Sub