M.cPhrase = CDOW(DATE())
MessageBox(Translate(M.cPhrase))
*** Traduction au travers de l'outil GOOGLE
FUNCTION Translate
LPARAMETERS cPhrase, cType
IF NOT EMPTY(M.cPhrase)
DO CASE
CASE VARTYPE(M.cType) <> 'C'
M.cType = "en%7Cfr"
CASE M.cType = "fr|en"
M.cType = "fr%7Cen"
CASE M.cType = "en|fr"
M.cType = "en%7Cfr"
OTHERWISE
M.cType = "en%7Cfr"
ENDCASE
ENDIF
M.cPhrase = ReadURL("http://translate.google.com/translate_t?text=" + ;
STRTRAN(M.cPhrase, ' ', '+') + "&langpair=" + M.cType + ;
"&hl=fr&ie=UTF8")
IF NOT EMPTY(M.cPhrase)
M.cPhrase = STREXTRACT(M.cPhrase, "<textarea name=q rows=5 cols=45 wrap=PHYSICAL>", ;
"</textarea>", 1, 1)
ENDIF
RETURN M.cPhrase
*---------------------------------------------------------------- ReadURL
FUNCTION ReadURL
LPARAMETERS pcUrlName, lQuiet
DECLARE INTEGER InternetOpen IN wininet.DLL STRING sAgent, ;
INTEGER lAccessType, STRING sProxyName, ;
STRING sProxyBypass, INTEGER lFlags
DECLARE INTEGER InternetOpenUrl IN wininet.DLL ;
INTEGER hInternetSession, STRING sUrl, STRING sHeaders, ;
INTEGER lHeadersLength, INTEGER lFlags, INTEGER lContext
DECLARE INTEGER InternetReadFile IN wininet.DLL INTEGER hfile, ;
STRING @sBuffer, INTEGER lNumberofBytesToRead, INTEGER @lBytesRead
DECLARE SHORT InternetCloseHandle IN wininet.DLL INTEGER hInst
#DEFINE INTERNET_OPEN_TYPE_PRECONFIG 0
#DEFINE INTERNET_OPEN_TYPE_DIRECT 1
#DEFINE INTERNET_OPEN_TYPE_PROXY 3
#DEFINE SYNCHRONOUS 0
#DEFINE INTERNET_FLAG_RELOAD 2147483648
LOCAL lsAgent, lhInternetSession, lhUrlFile, llOk, lnOk, lcRetVal,lcReadBuffer, lnBytesRead
* what application is using Internet services?
lsAgent = "VFP 6.0"
lcRetVal = ''
lhInternetSession = InternetOpen( lsAgent, INTERNET_OPEN_TYPE_PRECONFIG, ;
'', '', SYNCHRONOUS)
IF lhInternetSession = 0
IF NOT lQuiet
MessageBox("La session Internet ne peut pas Otre Ttablie !")
ENDIF
RETURN lcRetVal
ENDIF
lhUrlFile = InternetOpenUrl( lhInternetSession, pcUrlName, '', 0, ;
INTERNET_FLAG_RELOAD, 0)
IF lhUrlFile = 0
IF NOT lQuiet
MessageBox("L'URL <" + pcUrlName + "> n'est pas accessible !")
ENDIF
RETURN lcRetVal
ENDIF
llOk = .t.
DO WHILE llOK
* set aside a big buffer
lsReadBuffer = SPACE(65535)
lnBytesRead = 0
lnOK = InternetReadFile( lhUrlFile, @lsReadBuffer, LEN(lsReadBuffer),@lnBytesRead)
if ( lnBytesRead <> 0 )
lcRetVal = lcRetVal + left( lsReadBuffer, lnBytesRead )
endif
* error trap - either a read failure or read past eof()
llOk = ( lnOK = 1 ) and ( lnBytesRead <> 0 )
ENDDO
* close all the handles we opened
InternetCloseHandle( lhUrlFile )
InternetCloseHandle( lhInternetSession )
* return the URL contents
RETURN lcRetVal