因为时间太紧,无意冒范论坛规则,请大家原谅;
在DELPHI里,如何用google在线翻译页面里:http://translate.google.cn/translate_t?hl=zh-CN#把要翻译的内容提交上去,然后得到它翻译回来的中文;
希望大家能伸出温暖的十指,200元不多,当是和大家学习学习,谢谢

解决方案 »

  1.   


    function URLEncode(const S: string; const InQueryString: Boolean): string;
    var
      Idx: Integer; // loops thru characters in string
    begin
      Result := '';
      for Idx := 1 to Length(S) do
      begin
        case S[Idx] of
          'A'..'Z', 'a'..'z', '0'..'9', '-', '_', '.':
            Result := Result + S[Idx];
          ' ':
            if InQueryString then
              Result := Result + '+'
            else
              Result := Result + '%20';
          else
            Result := Result + '%' + SysUtils.IntToHex(Ord(S[Idx]), 2);
        end;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
       word: string;
       ms: TMemoryStream;
    begin
      ms := TMemoryStream.Create;
      word := Memo2.Text;
      IdHttp1.Get('http://translate.google.cn/translate_a/t?client=t&text=' + UrlEncode(Word, False) +'&sl=en&tl=zh-CN', ms);
      ms.Position := 0;
      Memo1.Lines.LoadFromStream(ms);
      ms.Free;
    end;
      

  2.   

    liangqingzhi 能先留下QQ吗,
    现在是如果翻译的字符超过一定数的时候会有抛出异常,你的方法比较简洁,能否再优化一下解决.
      

  3.   

    翻译达到一定长度需要post数据的,我懒得研究,你用4楼的代码
      

  4.   

    四楼的好像是有代码,但只提供DLL,liangqingzhi 兄弟能否救一下急帮研究一下.
      

  5.   

    用Get的方法的话长度有限制,用Post方法即可
      

  6.   

    楼上能说清楚一点吗,直接把
    IdHttp1.Get('http://translate.google.cn/translate_a/t?client=t&text=' + UrlEncode(Word, False) +'&sl=en&tl=zh-CN', ms);换成POST后,都没有数据回来了.
      

  7.   

    如果你懂HTTP协议的话,可以查看该页面的源代码,找到一个action="post"的form域.
      

  8.   

    谢谢楼上.我就是对HTTP不是很熟,
    http://translate.google.cn/translate_t?hl=zh-CN#能帮我看看吗,可能给个例子.
      

  9.   

    目前时间紧,没空看.其实最简单的就是你做一个转发程序(TIdTCPPortMap就可以),让浏览器通过你的转发程序出去,然后记录下流览器在文本比较多的时候,发的是什么样的报文(肯定是POST),再看看HTTP协议,依样画葫芦即可.