Click here to Skip to main content
14,360,905 members
Rate this:
Please Sign up or sign in to vote.
Hello all,

I'm new here and started programming with c++ only 2 months ago before I was mostly working with net. (vb). In net i was able to get my strings translated but in c++ I have no clue how to start to get my string translated from English to German and backward. I´m working with Visual studio Community 2015.

here my net code maybe someone can show me how to make it happen in c++, the best way for me would be without additional installations.

Private Function TranslateENGE(ByVal Textin As String(), ByVal ENtoGE As Boolean) As List(Of String)
                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"
                    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("" & "&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, "")

                Return TranslatedText

            Catch ex As Exception
                theUI.NXMessageBox.Show("Translation", NXMessageBox.DialogType.Error, ex.Message)
                Return Nothing
            End Try
        End Function

Thx much.

What I have tried:

I already search Codeguru but only found the Google API, also search in google, but without the needed results.
Richard MacCutchan 12-Oct-18 11:22am
I hate to say this but you would be better staying with VB.NET. Trying to convert this to C++ will be a big task since the C/C++ libraries do not support such a rich function set to get access to Web APIs.
Member 14017528 15-Oct-18 2:40am
Thx for the comment, but it could be achieved via c++ too if I understand correctly. What would I need to create out of nothing to achieve what my program needs.
Member 14017528 15-Oct-18 4:16am
Hi again, can I achieve what I intend to do with libcurl??
Member 14017528 21-Dec-18 6:06am
Hello, thx for the help i now made one program in C# and the other with c++ and combined them. Works fine thx.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100