Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

java - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...