读书人

利用微软通译API替代被停用谷歌翻译API

发布时间: 2012-09-15 19:09:29 作者: rapoo

利用微软翻译API替代被停用谷歌翻译API
众所周知,谷歌已经不支持翻译API1版本了,现在提供了API2的版本,主要是面对企业级用户,需要收费的。无奈之下使用微软提供的翻译API。
一、首先去http://code.google.com/p/microsoft-translator-java-api/,下载相关jar文件,这里有对微软翻译api的详细使用有作详细介绍。

二,去申请key,进入http://www.bing.com/developers/createapp.aspx,填写相关的你的应用信息就行了。就会有下面的图片中显示的key,中的Application ID就是key。

三、下面给个实例:

  /**   * @Title: MicroTranslate.java * @Description: TODO(用一句话描述该文件做什么) * @author zengzhaoshuai   * @date 2012-2-13 下午1:17:07 * @version V1.0   */import com.memetix.mst.language.Language;import com.memetix.mst.translate.Translate;/**  * @ClassName: MicroTranslate  * @Description: TODO(这里用一句话描述这个类的作用)  * @author zengzhaoshuai  * @date 2012-2-13 下午1:17:07  *   */public class MicroTranslate {public static void main(String[] args) throws Exception {    // Set the Microsoft Translator API Key - Get yours at http://www.bing.com/developers/createapp.aspx   // Translate.setKey(/* Enter your API Key here */);    Translate.setKey("自己申请的key");    String translatedText = Translate.execute("属性", Language.CHINESE_SIMPLIFIED, Language.ENGLISH);    System.out.println(translatedText);}}


四、运行结果:Property
1 楼 wulingbo2005 2012-04-10 翻译很慢啊

读书人网 >编程

热点推荐