|
String LANGPAIR_CN_EN = " zh-CN|en " ; // 汉语到英语
public static final String LANGPAIR_EN_CN = " en|zh-CN " ; // 英语到汉语
public static final String LANGPAIR_EN_JA = " en|ja " ; // 英语到日语
// 定义编码常数
public static final String CHARSET_CN = " GBK " ;
public static final String CHARSET_JA = " Shift_JIS " ;
// google在线翻译引擎url
static final String engineUrl = " http://translate.google.com/translate_t " ;
 /** */ /**
* 利用google在线翻译引擎实现翻译,并获取翻译内容
* @param translateText 要翻译的文本内容
* @param langpair 对译语言的值对,如en|ja是由英语翻译到日语
*/
public String translate(String translateText,String langpair)
 throws MalformedURLException,IOException,UnsupportedEncodingException {
// text是google翻译页面提交时对于欲翻译文字的变量名
// langpair是google翻译页面提交时对于采用何种互对语言的变量名
String urlstr = engineUrl + " ?text= " + encodeText(translateText) + " &langpair= " + langpair;
URL url = new URL(urlstr);
URLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty 上一页 [1] [2] [3] [4] [5] 下一页
|