Delphi 通过有道接口实现翻译


本文整理自网络,侵删。

 


function GetTranslatedText(const OriText: string): string;
var
  Json: TQJson;
const
  WebRestApiUrl = 'http://fanyi.youdao.com/translate?&doctype=json&type=AUTO&i=%s';
begin
  Json := TQJson.Create;
  try
    try
      Json.Parse(CSimpleGet(Format(WebRestApiUrl, [TURLEncoding.URL.Encode(OriText)]))); //CSimpleGet 这里可以搜索本站用 idhttp nethttpclient 实现获取
      Result := Json.ItemByPath('\translateResult[0][0]\tgt').AsString;
    except
      on e: Exception do
        Result := '';
    end;
  finally
    FreeAndNil(Json);
  end;
end;

感谢 黑夜杀手 提供

相关阅读 >>

Delphi 自带rest调试工具 restdebugger 用法

Delphi 通过http获取软件版本

Delphi 更改窗体为顶层窗体不闪烁

Delphi xe strpas 遇到的问题

Delphi不占cpu的延时函数

Delphi 关于rs485总线通信协议开发注意事项

pchar和array [0..255] of char的区别

Delphi中判断是否是64位操作系统

Delphi idhttp 设置cookie 和访问后读取cookie 值

Delphi 在firemonkey应用程序中使用torientationsensor获取设备倾斜和指南针航向

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...