ericnembot / google-api-translate-java

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

Google Translate API strange behavior on some devices #171

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Having some trouble with my app which uses the paid version of google 
translate. It works fine on several devices mostly (versions 2.2, 2.2.1, 2.3.5) 
the lower versions but throws an exception in 4.0

Error: [google-api-translate-java] Error retrieving translation.
Here is my code

public String translate(String InputText, String from, String to) {

    String key = ".........................";
    String translatedText = null;
    GoogleAPI.setHttpReferrer("http://android-er.blogspot.com/");
    GoogleAPI.setKey(key);

    Language fromLanguage = Language.valueOf(from);
    Language toLanguage = Language.valueOf(to);

    if (from.equals(to)) {
        translatedText = InputText;
    } else {
        try {
            translatedText = Translate.DEFAULT.execute(InputText,
                    fromLanguage, toLanguage);
        } catch (GoogleAPIException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            translatedText = "Error";
        }
    }
    return translatedText;
}

Note: I have tested the Google's Translate Application on all the devices and 
it works fine

Original issue reported on code.google.com by transvox...@gmail.com on 11 Jul 2012 at 4:07