danielgpratidya
New Member
- Joined
- Mar 21, 2014
- Messages
- 1
Hi,
I am new in this forum, but have monitored long time and have become a big fans of it.
This forum had helped me a lot in vba excel problems.
However this time I couldn't find any answer for my new issue to use translation.babylon.com
I have function which work perfectly with google translate using msxml2.xmlhttp and tried to modify it using the same method but I have lost because don't understand how to compose the url.
Here's the code I used for a long time using google translate and worked charmly (I got this from this marvelous forum as well ):
Function getGoogleTranslation(strSource As String, strSourceLang As String, strDestLang As String) As String
Dim strURL As String, x As String
strURL = "http://translate.google.com/translate_a/t?client=t&text=" & _
Replace(strSource, " ", "%20") & _
"&hl=en&sl=" & strSourceLang & _
"&tl=" & strDestLang & "&multires=1&pc=0&rom=1&sc=1"
With CreateObject("msxml2.xmlhttp")
.Open "get", strURL, False
DoEvents
.send
DoEvents
x = .responseText
End With
getGoogleTranslation = x
End Function
To use this function I used below codes extracting the results returned by analyzing any word functions available.
This below codes is not relevant though to my question (just need to describe what it does entirely).
Sub Translate
'Translated Words will be divided as each word functions
WordFunction = Split("conjunction,preposition,verb,noun,particle,adjective,prefix,interjection,suffix,complement", ",")
With ActiveSheet
SourceLang = "" 'Auto Detect so I leave it blank.
TargetLang = GetLang(.Range("B1")) 'GetLang is another function to convert eg: english > en, french > fr, etc...
'Get the total rows of data source
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
'Run a cycle through each rows
For r = 2 To lRow
If Not IsEmpty(str) Then
translateResults = getGoogleTranslation(str, SourceLang, TargetLang)
'Main Translated words
.Range("B" & r) = Replace(Replace(Split(translateResults, Chr(34) & "," & Chr(34))(0), "[", ""), """", "")
'Other words
col = 0
For Each c In WordFunction
WFpos = InStr(1, translateResults, c)
If WFpos > 0 Then
intStart = InStr(WFpos, translateResults, ",[") + 3
intEnd = InStr(intStart, translateResults, "],")
otherWords = Split(Replace(Mid(translateResults, intStart, intEnd - intStart), Chr(34), ""), ",")
For Each w In otherWords
.Cells(r, 3 + col) = w
col = col + 1
Next w
End If
Next c
End If
Next r
End With
End Sub
It would be great if someone can give me a clue on how to compose the correct url to use the translation.babylon website like used in above function with google translate:
strURL = "http://translate.google.com/translate_a/t?client=t&text=" & _
Replace(strSource, " ", "%20") & _
"&hl=en&sl=" & strSourceLang & _
"&tl=" & strDestLang & "&multires=1&pc=0&rom=1&sc=1"
I hope I am not confusing you, excuse me for my english, I am from Indonesia.
Thank you all excel expert, really appreciate your time to read this
Best Wishes,
Daniel G. Pratidya
I am new in this forum, but have monitored long time and have become a big fans of it.
This forum had helped me a lot in vba excel problems.
However this time I couldn't find any answer for my new issue to use translation.babylon.com
I have function which work perfectly with google translate using msxml2.xmlhttp and tried to modify it using the same method but I have lost because don't understand how to compose the url.
Here's the code I used for a long time using google translate and worked charmly (I got this from this marvelous forum as well ):
Function getGoogleTranslation(strSource As String, strSourceLang As String, strDestLang As String) As String
Dim strURL As String, x As String
strURL = "http://translate.google.com/translate_a/t?client=t&text=" & _
Replace(strSource, " ", "%20") & _
"&hl=en&sl=" & strSourceLang & _
"&tl=" & strDestLang & "&multires=1&pc=0&rom=1&sc=1"
With CreateObject("msxml2.xmlhttp")
.Open "get", strURL, False
DoEvents
.send
DoEvents
x = .responseText
End With
getGoogleTranslation = x
End Function
To use this function I used below codes extracting the results returned by analyzing any word functions available.
This below codes is not relevant though to my question (just need to describe what it does entirely).
Sub Translate
'Translated Words will be divided as each word functions
WordFunction = Split("conjunction,preposition,verb,noun,particle,adjective,prefix,interjection,suffix,complement", ",")
With ActiveSheet
SourceLang = "" 'Auto Detect so I leave it blank.
TargetLang = GetLang(.Range("B1")) 'GetLang is another function to convert eg: english > en, french > fr, etc...
'Get the total rows of data source
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
'Run a cycle through each rows
For r = 2 To lRow
If Not IsEmpty(str) Then
translateResults = getGoogleTranslation(str, SourceLang, TargetLang)
'Main Translated words
.Range("B" & r) = Replace(Replace(Split(translateResults, Chr(34) & "," & Chr(34))(0), "[", ""), """", "")
'Other words
col = 0
For Each c In WordFunction
WFpos = InStr(1, translateResults, c)
If WFpos > 0 Then
intStart = InStr(WFpos, translateResults, ",[") + 3
intEnd = InStr(intStart, translateResults, "],")
otherWords = Split(Replace(Mid(translateResults, intStart, intEnd - intStart), Chr(34), ""), ",")
For Each w In otherWords
.Cells(r, 3 + col) = w
col = col + 1
Next w
End If
Next c
End If
Next r
End With
End Sub
It would be great if someone can give me a clue on how to compose the correct url to use the translation.babylon website like used in above function with google translate:
strURL = "http://translate.google.com/translate_a/t?client=t&text=" & _
Replace(strSource, " ", "%20") & _
"&hl=en&sl=" & strSourceLang & _
"&tl=" & strDestLang & "&multires=1&pc=0&rom=1&sc=1"
I hope I am not confusing you, excuse me for my english, I am from Indonesia.
Thank you all excel expert, really appreciate your time to read this
Best Wishes,
Daniel G. Pratidya