Google Translation API?

edited October 2013 in How To...

Does anyone know how to use the current version of Google's language translation API? I would love to get some sample code... I do know it's a paid service now, so the old example from the original forum no longer applies and the API documentation is a little too Java-ey for me right now.

Answers

  • edited October 2013

    To get you started, looks like what you have to do is:

    a) get application key from google

    b) now you should be able to do:

    String url = "https" + ":" + "//"; 
    // i have to glue this strings like this
    // because if i write it normally processing forum will convert it to link and it will look messy.
    url += "/language/translate/v2?key=INSERT-YOUR-KEY&q=hello%20world&source=en&target=de";
    String[] googleResponse = loadStrings(url);
    
    if ( googleResponse != null){
    for(String line: googleResponse){
        println(line); // this will print raw JSON reply from google server
    }
    }
    else{
       println("Google replied with empty response");
    }
    

    later you need to glue together into one string googleResponse array and parse it with JSON.

  • Thanks Dimkir, I'm still new to the 'Processing way' and wasn't sure how to inject html requests (or indeed whether I had to at all). I'll give it a try and post back my results.

Sign In or Register to comment.