public String baiduTranslate(String strToTranslate, String fromLanguage, String toLanguage) { String translatedStr = ""; String encodedStr = HttpUtility.UrlEncode(strToTranslate); String baiduTransBaseUrl = "http://openapi.baidu.com/public/2.0/bmt/translate?client_id=YEBdxswo4u7Oe21Y2LYcfz9I&q="; String baiduTransUrl = baiduTransBaseUrl; baiduTransUrl += encodedStr; baiduTransUrl += "&from=" + fromLanguage; // source language baiduTransUrl += "&to=" + toLanguage; // to language crifanLib cri = new crifanLib(); //使用crifanlib库 try { String transRetHtml = cri.getUrlRespHtml(baiduTransUrl); String[] str = transRetHtml.Split(new String[] { "\"dst\"" }, StringSplitOptions.RemoveEmptyEntries); cri.extractSingleStr(":\"(.+?)\"}]}", str[1], out translatedStr); translatedStr = System.Text.RegularExpressions.Regex.Unescape(translatedStr);//解码escape形式的Unicode,即将反斜杠u加上数字的字符 //获得fromLanguage语言 int index = transRetHtml.IndexOf("\",\"to\""); String fl = transRetHtml.Substring(9, index - 9); tts = "http://tts.baidu.com/text2audio?lan=" + fl; tts += "&ie=UTF-8&text=" + encodedStr; } catch { } return(translatedStr); }
public crifanLibGoogle() { //!!! for load embedded dll: (1) register resovle handler AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); //init something crl = new crifanLib(); }
public completeHint() { InitializeComponent(); curParentForm = null; crl = new crifanLib(); onlyShowFoler = false; }
public string googleTranslate(String strToTranslate, String fromLanguage, String toLanguage) { String translatedStr = ""; String encodedStr = HttpUtility.UrlEncode(strToTranslate); String googleTransBaseUrl = "http://translate.google.cn/translate_a/single?client=t"; String googleTransUrl = googleTransBaseUrl; googleTransUrl += "&sl=" + fromLanguage; // source language googleTransUrl += "&tl=" + toLanguage; // to language googleTransUrl += "&hl=zh-CN&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&q="; googleTransUrl += encodedStr; crifanLib cri = new crifanLib(); //使用crifanlib库 try { String transRetHtml = cri.getUrlRespHtml(googleTransUrl); int index1 = transRetHtml.IndexOf("\",,,"); String str1 = transRetHtml.Substring(0, index1); int index2 = str1.IndexOf(",[,,"); if (index2 > 0) { str1 = str1.Substring(3, index2 - 3); } else { str1 = str1.Substring(3, str1.Length - 3); } String[] str = str1.Split(new String[] { "],[" }, StringSplitOptions.RemoveEmptyEntries); String ss = ""; foreach (String s in str) { if (cri.extractSingleStr("\"(.+?)\",\".+?\"", s, out ss)) { translatedStr += ss; } } String fl = "en"; String str2 = transRetHtml.Substring(index1 - 7, 8); cri.extractSingleStr("\"(.+?)\"", str2, out fl); tts = "http://translate.google.cn/translate_tts?ie=UTF-8&tl=" + fl; tts += "&total=1&prev=input&q="; } catch { } return(translatedStr); }
public songtaste() { crl = new crifanLib(); AppDomain.CurrentDomain.AssemblyResolve +=new ResolveEventHandler(CurrentDomain_AssemblyResolve); }
//specify your logger public crifanLibAmazon(Logger logger) { //!!! for load embedded dll: (1) register resovle handler AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); //init something crl = new crifanLib(); gLogger = logger; }
public songtaste() { crl = new crifanLib(); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); }