惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
Jina AI
Jina AI
雷峰网
雷峰网
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
博客园 - 司徒正美
罗磊的独立博客
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Vercel News
Vercel News
A
About on SuperTechFans
I
InfoQ
D
DataBreaches.Net
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队

博客园 - 骑人的驴

windows升级到1607后操作很卡顿的解决办法 打包解决方案后,安装时提示只能在IIS5.1以上运行解决方法 在CS代码页获取input输入框内肉----.net学习点滴 showModalDialog和showModelessDialog的变量传递 在.net中webform弹出窗口输入后返回值实现方法 quickreport4.5安装--for delphi6.0 QuickCHM2.6出现"不支持此接口" 的两种解决办法(转) 网上找到的,记下来(API函数4) 网上找到的,记下来(API函数3) 网上找到的,记下来(API函数2) - 骑人的驴 - 博客园 网上找到的,记下来(API函数1) delphi字符串函数大全 SQL SERVER 与ACCESS、EXCEL的数据转换 几个知识点 JavaScript实用的一些技巧 关于ASP.NET网页编程的几个技巧 asp.net开发常用技巧收集 SQL Server 的通用分页显示存储过程 C#常用函数
在 Delphi 中使用微软全文翻译的小例子
骑人的驴 · 2011-11-25 · via 博客园 - 骑人的驴

转自http://www.delphigear.cn/0/7913/go.aspx

需要先去申请一个 AppID: http://www.bing.com/toolbox/bingdeveloper/
使用帮助在: http://msdn.microsoft.com/en-us/library/dd576287.aspx



uses MsXML; {函数} function Translate(AAppID: string; AText: string; InLanguage: string='en'; OutLanguage: string='zh-CHS'): string; const   BaseUrl = 'http://api.microsofttranslator.com/V2/http.svc/Translate?appId=%s&text=%s&from=%s&to=%s'; var   Url: string;   req: IXMLHTTPRequest; begin   Url := Format(BaseUrl, [AAppID, AText, InLanguage, OutLanguage]);   req := CoXMLHTTP.Create;   req.open('Get', Url, False, EmptyParam, EmptyParam);   req.send(EmptyParam);   Result := req.responseText;   Result := Copy(Result, 68+1, Length(Result)-68-9); //去掉前后的标签 end; {调用测试} procedure TForm1.Button1Click(Sender: TObject); const   myAppId = '65FCA293BDB85C98D16A567C3FECE22272B6****'; //这是我申请的 AppID, 隐藏了后四位 begin   Memo2.Text := Translate(myAppId, Memo1.Text); end;


效果图:


使用 Indy:

uses IdHTTP;

function Translate2(AAppID: string; AText: string; InLanguage: string='en'; OutLanguage: string='zh-CHS'): string;
const
  BaseUrl = 'http://api.microsofttranslator.com/V2/http.svc/Translate?appId=%s&text=%s&from=%s&to=%s';
var
  Url: string;
  stream: TStringStream;
  idHttpObj: TIdHTTP;
begin
  stream := TStringStream.Create;
  idHttpObj := TIdHTTP.Create(nil);
  Url := Format(BaseUrl, [AAppID, Trim(AText), InLanguage, OutLanguage]);
  idHttpObj.Get(Url, stream);
  Result := stream.DataString;
  Result := Copy(Result, 68+1, Length(Result)-68-9); //去掉前后的标签
  idHttpObj.Free;
  stream.Free;
end;