salggarcia / google-api-for-dotnet

Automatically exported from code.google.com/p/google-api-for-dotnet
0 stars 0 forks source link

???????? Invalid Language Translation pair exception #59

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Visual studio 2008 on windows  xp sp2
Sample code...
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If comboSrc.Text = Nothing Or comboDest.Text = Nothing Then
            MsgBox("Please select source & destination languages", MsgBoxStyle.Information)
            Exit Sub
        End If
        If Trim(txtSource.Text) = Nothing Then
            MsgBox("Please enter text", MsgBoxStyle.Information)
            Exit Sub
        End If
        Try
            Dim trans As New Google.API.Translate.TranslateClient("http://www.google.co.in")
            Dim src, dest As Google.API.Translate.Language
            If LCase(comboSrc.Text) = "english" Then
                src = Google.API.Translate.Language.English
            ElseIf LCase(comboSrc.Text) = "hindi" Then
                src = Google.API.Translate.Language.Hindi
            ElseIf LCase(comboSrc.Text) = "kannada" Then
                src = Google.API.Translate.Language.Kannada
            ElseIf LCase(comboSrc.Text) = "telugu" Then
                src = Google.API.Translate.Language.Telugu
            ElseIf LCase(comboSrc.Text) = "tamil" Then
                src = Google.API.Translate.Language.Tamil
            ElseIf LCase(comboSrc.Text) = "malayalam" Then
                src = Google.API.Translate.Language.Malayalam
            End If
            '//-------------------------------------------------
            If LCase(comboDest.Text) = "english" Then
                dest = Google.API.Translate.Language.English
            ElseIf LCase(comboDest.Text) = "hindi" Then
                dest = Google.API.Translate.Language.Hindi
            ElseIf LCase(comboDest.Text) = "kannada" Then
                dest = Google.API.Translate.Language.Kannada
            ElseIf LCase(comboDest.Text) = "telugu" Then
                dest = Google.API.Translate.Language.Telugu
            ElseIf LCase(comboDest.Text) = "tamil" Then
                dest = Google.API.Translate.Language.Tamil
            ElseIf LCase(comboDest.Text) = "malayalam" Then
                dest = Google.API.Translate.Language.Malayalam
            End If

            txtDest.Text = trans.Translate(txtSource.Text, src, dest, Google.API.Translate.TranslateFormat.Text)

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

What is the expected output? What do you see instead?
expected output: translated text in selected destination language
result: exception

What version of the product are you using? On what operating system?
GoogleTranslateAPI_0.3
Windows XP Professional SP2

Please provide any additional information below.

Google.API.GoogleServiceException was caught
  Message="[response status:400]invalid translation language pair"
  ResponseDetails="invalid translation language pair"
  ResponseStatus=400
  Source="GoogleTranslateAPI"
  StackTrace:
       at Google.API.RequestUtility.GetResponseData[T,TService](RequestCallback`2 request, Uri address, Binding binding, String referrer)    at Google.API.GoogleClient.GetResponseData[T,TService](RequestCallback`2 request)    at Google.API.Translate.TranslateClient.NativeTranslate(String text, String from, String to, String format)    at Google.API.Translate.TranslateClient.Translate(String text, String from, String to, String format)    at LanguageAPISample1.Form1.Button1_Click(Object sender, EventArgs e) in D:\Aryah Soft\Software_Lab\winApps\LanguageAPISample1\LanguageAPISample1\Form1.vb:line 51
  InnerException: 

Original issue reported on code.google.com by sreeniva...@gmail.com on 18 Jun 2010 at 7:06

GoogleCodeExporter commented 8 years ago
i have the same problem Please answer !

Original comment by Al.Waz...@gmail.com on 12 Aug 2010 at 2:55

GoogleCodeExporter commented 8 years ago
This isn't a defect. Read the exception. It says Invalid Translation Language 
Pair.

That means you can't translate from that source to that destination.

E.g. You can't do Swahili to Uzbek.

You need to look for this error and deal with it as appropriate in your code

Original comment by t3roar@gmail.com on 6 Jan 2011 at 12:18

GoogleCodeExporter commented 8 years ago
This IS a defect.  Also the sample code does not work, Translating from English 
to German for instance is completely valid.

Translate(string, string, string) does not work at all with
client.Translate("word", Language.English, Language.German) as the Language 
objects aren't strings either.

Original comment by aa...@muldr.com on 8 Jan 2011 at 3:47

GoogleCodeExporter commented 8 years ago
I also have to say that this is a problem.

TranslateClient client = new TranslateClient("");
translated = client.Translate(str, Language.English, Language.German);

is not valid because the Translate method only accepts strings for all 
arguments, not Language objects.

trying

TranslateClient client = new TranslateClient("");
translated = client.Translate(str, Convert.ToString(Language.English), 
Convert.ToString(Language.German));

Does not work either as you end up getting the error about invalid language 
pairs.

Types do not match up between the method and the Language objects, and also 
doing the next logical thing of Convert.ToString on the Language objects does 
not work...

I am unable to use this API as it currently is.

Original comment by magus.x...@gmail.com on 7 Feb 2011 at 3:06

GoogleCodeExporter commented 8 years ago
I have the exact problem translating from Greek to English

Original comment by pap...@gmail.com on 9 Feb 2011 at 1:33

GoogleCodeExporter commented 8 years ago
Ok Found the porblem
There is a bug in the api. 
Translate method of the TranslateClient accepts strings for language 
definition. 
However 
Google.API.Translate.Language.Greek is enumeration that is not implicitly 
converted to the correct literal. 

The solution was to give the correct strings manually: 

String Text = translateClient.Translate("Έλα Μάνα", "el", "en")

regs

Original comment by pap...@gmail.com on 9 Feb 2011 at 1:42

GoogleCodeExporter commented 8 years ago
I'm not able to convert Indian language other than hindi.

Actual problem is Google.API.Translate.Language.Tamil.IsTranslatable is default 
false.

how can i made true 

Original comment by kirubamc...@gmail.com on 25 Apr 2011 at 9:08

GoogleCodeExporter commented 8 years ago
Hi friends,

here is the code I used to translate English to Oriya

            string str = "I belong to orissa";

            Google.API.Translate.TranslateClient client = new Google.API.Translate.TranslateClient("http://www.google.co.in");
            str = client.Translate(str, Google.API.Translate.Language.English.ToString(), Google.API.Translate.Language.Hindi.ToString());
            Response.Write(str);

but i got the error stating invalid language pair.

Please let me know how to solve the issue

Original comment by mahapatr...@gmail.com on 6 Dec 2011 at 6:09