Private Function TranslateENGE(ByVal Textin As String(), ByVal ENtoGE As Boolean) As List(Of String) Try If Not HaveInternetConnection() Then theUI.NXMessageBox.Show("No internet", NXMessageBox.DialogType.Information, "No internet connection available, please establish a connection to the internet and click the button again.") Return Nothing End If Dim targetlang As String = "" Dim sourcelang As String = "" If ENtoGE Then '& tolangid & "&hl=" & fromlangid & sourcelang = "en" targetlang = "de" Else sourcelang = "de" targetlang = "en" End If 'create text for input into one string Dim input As String = String.Join(vbNewLine, Textin) input = HttpUtility.UrlEncode(input) Dim TranslatedText As New List(Of String) Dim WbC As New WebClient WbC.Encoding = Text.Encoding.UTF8 Dim url As String = WbC.DownloadString("https://translate.googleapis.com/translate_a/single?client=gtx" & "&ie=UTF-8" & "&oe=UTF-8" & "&sl=" & sourcelang & "&tl=" & targetlang & "&dt=t" & "&dt=bd" & "&dj=1" & "&source=icon" & "&q=" & input) ' & "&oe=UTF-8" & &dt=bd Utf 8 is default Dim Json1 As JObject = JObject.Parse(url) Dim result As String = "" For i As Integer = 0 To Json1.SelectToken("sentences").Count - 1 result = Json1.SelectToken("sentences[" & i & "]").SelectToken("trans").ToString() result = result.Replace(vbNewLine, "") TranslatedText.Add(result) Next Return TranslatedText Catch ex As Exception theUI.NXMessageBox.Show("Translation", NXMessageBox.DialogType.Error, ex.Message) Return Nothing End Try End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)