I use the code below to translate text in diferent languages , problem is that only first word is translated and the text does not return entirely ?
Is there a problem in the code or this is how the service works ?
Is there a problem in the code or this is how the service works ?
B4X:
Sub translate(text As String,source As String , destination As String)
Dim job As HttpJob
Dim transtr As String = 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 = source
Dim dstlang As String = destination
Dim poststr As String = "https://Translate.googleapis.com/translate_a/single?client=gtx&sl=" & _
srclang & "&tl=" & dstlang & "&dt=t&q=" & transtr
job.PostString(poststr, "")
job.GetRequest.SetHeader("Content-Type", "application/json")
job.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0")
job.GetRequest.SetContentType("application/json")
job.GetRequest.SetContentEncoding("text/plain")
'lbOut.Text = ""
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