Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Translator API and many translation for one word

I am using google-api-translate-java-0.92.jar.


Translate.setHttpReferrer("http://translate.google.com/");
        try {
            String translation = Translate.execute("arrangement", Language.ENGLISH, Language.UKRANIAN);
            System.out.println(translation);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

But I get only one translation. I go to page http://translate.google.com/ and It gives me multiple translation. How can I get multiple translation from my code?

like image 238
Victoria Seniuk Avatar asked Oct 12 '10 14:10

Victoria Seniuk


2 Answers

I don't believe you can...

Looking at the soucre, it builds up the following URL:

http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=en|uk&q=arrangement

which when you look at the JSON response, returns:

{"responseData": {"translatedText":"Композиція"}, "responseDetails": null, "responseStatus": 200}

As you can see, this is only returning a single word. The dictionary lookup on the google translate page must be an additional call to a different service (not part of the translate service)


EDIT

Using firebug, you can see the request that is being made by the translate page, and you get this URL:

http://translate.google.com/translate_a/t?client=t&text=arrangement&hl=en&sl=en&tl=uk&multires=1&otf=2&pc=0&sc=1

Which returns this:

[[["Композиція","arrangement","Kompozytsiya"]],[["noun",["розташування","розміщення","домовленість","аранжування","упорядкування","механізм","оформлення","пристрій","систематизація","монтаж","пристосування","урегулювання","плани","згода","залагода","розв'язання","порозуміння"]]],"en"]

However, this extended URL format is not supported by the translate JAR you are using (at least I can't find it in the source on google code), is not part of the googleapis subdomain, and I'm not even sure it's for public consumption or that calling it directly doesn't violate Googles T&Cs.

But that's how they generate the dictinary list anyway...

like image 82
tim_yates Avatar answered Sep 26 '22 14:09

tim_yates


From Google Translate API FAQ (checked: 16 November 2013)

Is it possible to get multiple translations of a word?

The answer:

No. This feature is only available via the web interface at translate.google.com

source: https://developers.google.com/translate/v2/faq#technical

like image 45
andilabs Avatar answered Sep 23 '22 14:09

andilabs