google翻译api已经收费了,而微软翻译api目前是免费的,支持几种不同的方式访问,如果感兴趣可以自己封装下协议处理。官方介绍:
。
这里介绍一下java下的使用。Java下使用微软翻译api可以直接使用一个开源的sdk,。
一、首先去,下载相关jar文件,这里有对微软翻译api的详细使用有作详细介绍。
二,去申请key,进入,填写相关的你的应用信息就行了。就会有下面的图片中显示的key,中的Application ID就是key。
三、下面给个实例:
Java代码
- /**
- * @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
- // 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、android下要用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的免费流量,操作如下:
ake 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)