Google Translator API and many translation for one word

前端 未结 3 1004
离开以前
离开以前 2020-12-16 04:51

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


Translate.setHttpReferrer(\"http://translate.g         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-16 05:20

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

提交回复
热议问题