hola de nuevo,
google ha cerrado la api del traductor y he encontrado que microsoft tinen tambien una api.
he encontrado el siguiente codigo para utilizar esta api
Código Delphi
[-]
const
MicrosoftTranslatorTranslateUri = 'http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=%s&text=%s&from=%s&to=%s';
BingAppId = '7FA9D0A8FB6B194BE57E92B286FCAF0B774883F3';
Msxml2_DOMDocument = 'Msxml2.DOMDocument.6.0';
function TDML.TranslateText(const AText, SourceLng, DestLng: string): string;
var
XmlDoc : OleVariant;
Node : OleVariant;
begin
Result:=WinInet_HttpGet(Format(MicrosoftTranslatorTranslateUri,[BingAppId,AText,SourceLng,DestLng]));
XmlDoc:= CreateOleObject(Msxml2_DOMDocument);
try
XmlDoc.Async := False;
XmlDoc.LoadXML(Result);
if (XmlDoc.parseError.errorCode <> 0) then
raise Exception.CreateFmt('Error in Xml Data %s',[XmlDoc.parseError]);
Node:= XmlDoc.documentElement;
if not VarIsClear(Node) then
Result:=XmlDoc.Text;
finally
XmlDoc:=Unassigned;
end;
end;
procedure TDML.WinInet_HttpGet2(const Url: string; Stream: TStream);
const
BuffSize = 1024*1024;
var
hInter : HINTERNET;
UrlHandle: HINTERNET;
BytesRead: Longword;
Buffer : Pointer;
begin
hInter := InternetOpen('', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(hInter) then
try
Stream.Seek(0,0);
GetMem(Buffer,BuffSize);
try
UrlHandle := InternetOpenUrl(hInter, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then
begin
repeat
InternetReadFile(UrlHandle, Buffer, BuffSize, BytesRead);
if BytesRead>0 then
Stream.WriteBuffer(Buffer^,BytesRead);
until BytesRead = 0;
InternetCloseHandle(UrlHandle);
end;
finally
FreeMem(Buffer);
end;
finally
InternetCloseHandle(hInter);
end;
end;
function TDML.WinInet_HttpGet(const Url: string): string;
Var
StringStream : TStringStream;
begin
Result:='';
StringStream:=TStringStream.Create('');
try
WinInet_HttpGet2(Url,StringStream);
if StringStream.Size>0 then
begin
StringStream.Seek(0,0);
Result:=StringStream.ReadString(StringStream.Size);
end;
finally
StringStream.Free;
end;
end;
el probela que tengo es que estoy trabajando con delphi 6 y en el codigo que encontre utiliza la siguiente declaración :
Código Delphi
[-]StringStream:=TStringStream.Create('',TEncoding.UTF8);
esto no funciona con mi delphi y no se como passar a UTF8 el resultado de la traducción