利用百度翻译API实现多语言的翻译
         
          
        发表时间:2020-10-19
        发布人:葵宇科技
        浏览次数:89
       
          
		  
中英、英中、每日、日中、中韩、韩中、中法、法中、中西、西中、中泰、泰中、中阿、阿中、中俄、俄中、英日、日英、英泰、泰英、英阿、阿英、英西、西英、英葡、葡英
频率限制:
通俗开辟者供给1000次/小时限制,支撑扩容;
GET请求方法:
响应示例:
{"from":"en","to":"zh","trans_result":[{"src":"today","dst":"\u4eca\u5929"}]}
                            codes[0] = (byte)code2;//必须是小端在前
今朝支撑11种说话,如下所示:
西班牙语  spa  法语  fra 
泰语  th  阿拉伯语  ara 
日语  jp  韩语  kor 
                    {
俄罗斯语  ru  葡萄牙语  pt 
粤语  yue  文言文  wyw 
白话文  zh  主动检测  auto 
步调:
Step1. 申请ApiKey,http://developer.baidu.com/console#app/project
Step2. 构成Get请求
Step3. 获得响应
Step4. 对响应进行解析(关键)
Step5. 结不雅输出
关键代码(C#):
public string getTraslation(string src)
支撑说话:
        {
            //发送请求
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://openapi.baidu.com/public/2.0/bmt/translate?client_id="
 + client_id + "&q=" + src + "&from=" + from + "&to=" + to);
//获得响应
            string res = string.Empty;
            try
                //获取响应流
                HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                res = reader.ReadToEnd();
                reader.Close();
                response.Close();
//正则表达式
                string pattern = @"""dst"":""(?.*?)""}";
                MatchCollection matchs;