Salvador Pasquier Salvador Pasquier - 1 year ago 119
Java Question

How do you make a request for a translation with the Google Translate v2 API Client Library for java?

There aren't examples on how to use Google Translate API Cliente library for java.

In this page Google suggest to search examples for their APIs but there is not a single one for Google Translate API:

Since I didn't found any example for Google Translate API I don't have any clue about how to use their official java library.

I want to make a simple request to translate a text (for example Hello World from english to spanish) with the Official library made by Google: but there is no documentation or examples available for the public.

Does anyone have info about how to use Google Translate API client library in java, I already googled and I had no luck at all.

I already have included all the jars to my project, but I don't know which classes I must use or which objects instantiate to make a translation from one language to another. I have no clue at all. I just need a simple snipped of code like in the examples repositories for other Google APIs.

Jan Jan
Answer Source

Here's a working example.

You need to have your own App-Key generated for your app (start here) as translate API is no longer publicly available.

For options what to pass into Translate.Builder() see here.

import java.util.Arrays;


public class TranslateMe {

    public static void main(String[] args) {

        try {           
            // See comments on 
            // on options to set
            Translate t = new Translate.Builder(
                    ,, null)                                   
                    //Need to update this to your App-Name
            Translate.Translations.List list = Translations().list(
                            //Pass in list of strings to be translated
                            "Hello World",
                            "How to use Google Translate from Java"), 
                        //Target language   
            //Set your API-Key from
            TranslationsListResponse response = list.execute();
            for(TranslationsResource tr : response.getTranslations()) {
        } catch (Exception e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download