Google翻译API和一个单词的许多翻译 [英] Google Translator API and many translation for one word

查看:99
本文介绍了Google翻译API和一个单词的许多翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用google-api-translate-java-0.92.jar.

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());
        }

但是我只有一个翻译.我转到页面 http://translate.google.com/,它为我提供了多种翻译.如何从我的代码中获得多个翻译?

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?

推荐答案

我不相信你可以...

I don't believe you can...

查看来源,它会建立以下URL:

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

当您查看JSON响应时,它返回:

which when you look at the JSON response, returns:

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

如您所见,这仅返回一个单词. Google翻译页面上的字典查找必须是对其他服务的附加调用(不属于翻译的一部分)服务)

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)

编辑

使用萤火虫,您可以看到翻译页面发出的请求,并获得以下URL:

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

哪个返回此:

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

但是,您使用的翻译JAR不支持这种扩展的URL格式(至少我在

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

这篇关于Google翻译API和一个单词的许多翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆