首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

调用google通译

2012-09-15 
调用google翻译import com.google.api.translate.Language import com.google.api.translate.Translate

调用google翻译
import com.google.api.translate.Language; import com.google.api.translate.Translate; ??public class MyTranslate { ????public static void main(String args[]) { ????????if(args.length != 2) { ????????????System.out.println("run like this:java -jar transtalor.jar? word"); ????????????System.exit(1); ????????} ??????????????????try { ????????????String languageFrom = null; ????????????String languageTo = null; ????????????if (args[0].equals("ce")) { // 中到英 ????????????????languageFrom = Language.CHINESE; ????????????????languageTo = Language.ENGLISH; ????????????} else if (args[0].equals("ec")) { // 英到中 ????????????????languageFrom = Language.ENGLISH; ????????????????languageTo = Language.CHINESE; ????????????} else { ????????????????System.out.println("run like this:java -jar transtalor.jar? word"); ????????????????System.exit(1); ????????????} ??????????????System.out.println(Translate.translate(args[1], languageFrom, languageTo)); ????????} catch (Exception ex) { ????????????System.out.println("UnkownError!"); ????????}??????? ????} }

热点排行