How to use Google translate API from code

守給你的承諾、 提交于 2019-12-10 19:51:38

问题


I am trying to create an app that send a word to translate.google.com, take the result of the translation and display it to the user. I composed the URL but I do not know how to extract the word/phrase from the webpage.

Example pseudo: en is code for english and es is code for spanish

String from = "en";
String to = "es";
String word = "hello"; //this will be user input text really
String URL = "http://www.translate.google.com/#" + from + "/" + to + "/" + word;

Therefore the request URL will look like http://www.translate.google.com/#en/es/hello

I now need to be able to retrieve the information from the result box and place it in a String so I can display it to the user.


回答1:


Google translate provide API for retrieving translations. You should use json object and GET request to the google translate server. In this link you can find the official Developer's Guide with code examples.



来源:https://stackoverflow.com/questions/14789937/how-to-use-google-translate-api-from-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!