微软翻译api的使用介绍和注意事项

 google翻译api已经收费了,而微软翻译api目前是免费的,支持几种不同的方式访问,如果感兴趣可以自己封装下协议处理。官方介绍:

http://msdn.microsoft.com/en-us/library/hh454950.aspx

这里介绍一下java下的使用。Java下使用微软翻译api可以直接使用一个开源的sdkhttp://code.google.com/p/microsoft-translator-java-api/

 

 一、首先去http://code.google.com/p/microsoft-translator-java-api/,下载相关jar文件,这里有对微软翻译api的详细使用有作详细介绍。 

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

  三、下面给个实例: 

Java代码  

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

 

四、运行结果:Property 

 

这里说下可能出现的问题:

1android下要用microsoft-translator-java-api-0.6-jar-with-dependencies.jar,否则运行时可能会报错android java.lang.NoClassDefFoundError: org.json.simple.JSONValue

2、使用过程中出现错误:TranslateApiException: Cannot find an Azure Market Place Translator Subscription associated with the request credentials,则需要到网址上先订阅translate api的免费流量,操作如下:

Make sure you login to azure market place  click on data and select Microsoft Translator. Now click on 2000000 c/moth @ $0 update option. Now I think this error will go away. Try following link also. This is the link where I signed up for 2000000 c/month offer. I was facing the same problem but when I updated my account through following link, this error went away.(参考:http://social.msdn.microsoft.com/Forums/zh-CN/microsofttranslator/thread/1eeb0066-553f-4523-9a1b-0976e4205bb2)

转载于:https://www.cnblogs.com/brainy/archive/2012/05/24/2516487.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值