微軟翻譯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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM