giszh86 / google-api-translate-java

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

Error retrieving translation & ajax.googleapis.com #142

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I will try to provide as much information as possible. I have tried all methods 
mentioned in preceding issues so far but none have solved my problem.

I am using this API for an Android application I am building, but I am 
currently testing this code in the debugger of an Eclipse IDE.

What steps will reproduce the problem?
1.

I have set my Network Connections (Preferences -> Network Connections).

Active Provider: Manual

HTTP Host=localhost Port=80
HTTPS Host=localhost Port=80
SOCKS Host=localhost Port=80

2.

I have set my internet permissions in the AndroidManifest.xml:

android.permission.INTERNET

3.

My code is shown below:

package com.app;

import java.util.Properties;

import com.google.api.translate.Language;
import com.google.api.translate.Translate;

public class TransCamTranslator {
    private String _text = "";

    // Impement as singleton?
    public TransCamTranslator(String fromLanguage, String toLanguage, String text){
        _text = text;

        System.getProperties().put("http.proxySet", "true");
        System.getProperties().put("http.proxyHost", "localhost");
        System.getProperties().put("http.proxyPort", "80");

        try{
            //Translate.setHttpReferrer("http://localhost/");
            Translate.setHttpReferrer("localhost");
            String translation = Translate.execute(text, Language.ENGLISH, Language.FRENCH);
            System.out.println("Source text: " + text);
            System.out.println("Target text:" + translation);
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }
    }

}

What is the expected output? What do you see instead?

Expected:
An output of the translated string.

Actual:
java.lang.Exception: [google-api-translate-java] Error retrieving translation.
java.net.UnknownHostException: ajax.googleapis.com

What version of the product are you using? On what operating system?

google-api-translate-java-0.95

Please provide any additional information below.

I must admit that I am new to the use of proxies in my application - so I am 
not sure if what I have is the correct set up? At the moment I would just like 
to have it set up on my local machine but will this have to change once I start 
testing this on the Android device?

I will be grateful for any advice or tips you may have and I will cooperate 
100%. If we solve the solution - I am willing to post the full steps that I 
took to get this working in the hope to help others.

Kind regards,

Lee 

Original issue reported on code.google.com by orochima...@hotmail.co.uk on 13 May 2011 at 11:57

GoogleCodeExporter commented 9 years ago
It appears that I had to manually modify the AndroidManifest.xml by opening up 
the file and adding the XML myself.

I also had to manually add the .Jar entry into Classpath. 

Very strange as I haven't had this problem before. However it works now and I 
recommend others who are having similar problems to check these files and make 
sure they are correct.

Your Classpath file should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="lib" path="lib/google-api-translate-java-0.95.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Your AndroidManifest.xml file should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.TransCam"
      android:versionCode="1"
      android:versionName="1.0">
<uses-permission
        android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:permission="android.permission.INTERNET">
        <activity android:name=".Camera"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

Good luck!

Original comment by orochima...@hotmail.co.uk on 14 May 2011 at 10:44

GoogleCodeExporter commented 9 years ago

Original comment by rich.mid...@gmail.com on 5 Nov 2011 at 5:20