我想开发一个Android应用程序,它可以从英语转换为术语和术语到英语。有任何API可以做到这一点。最好的方法是什么。
答案 0 :(得分:0)
您可以将谷歌api用于此目的
private final String requestURLTranslation = "https://www.googleapis.com/language/translate/v2?key=";
private final String requestKey = "INSERT-YOUR-KEY";
private final String requestSrc = "&source=";
private final String requestDst = "&target=";
private final String requestTxt = "&q=";
public String requestTranslationForGoogle( String plaintext, String source, String destination ) {
String request = requestURLTranslation + requestKey + requestSrc + source + requestDst + destination + requestTxt;
try {
request += URLEncoder.encode( plaintext, "UTF-8" );
URL url = new URL( request );
URLConnection connection = url.openConnection();
connection.connect();
InputStreamReader inputStreamReader = new InputStreamReader( connection.getInputStream(), "UTF-8" );
BufferedReader in = new BufferedReader( inputStreamReader, 512 );
StringBuffer sb = new StringBuffer();
String line;
while ( ( line = in.readLine() ) != null ) {
sb.append( line );
}
in.close();
return sb.toString();
}
catch ( Exception e ) {
e.printStackTrace();
}
return null;
}
注意:代码将返回应进一步解析的json数据
请访问
1)https://github.com/Rookery/google-api-translate-android
旁边的