Import initial din SVN ROAAUTO/Trunk @HEAD
This commit is contained in:
73
COMUN/utile/Google Translator/google.prg
Normal file
73
COMUN/utile/Google Translator/google.prg
Normal file
@@ -0,0 +1,73 @@
|
||||
CLOSE DATABASES
|
||||
SET DELETED ON
|
||||
SET CENTURY on
|
||||
SET ANSI ON
|
||||
SET EXACT ON
|
||||
*!* SET DEFAULT TO "d:\roa_trunk\roastart\locale"
|
||||
USE locale IN 0 SHARED
|
||||
|
||||
*Use test
|
||||
oGt = Createobje("ugt") && ,"google.prg")
|
||||
|
||||
SELECT locale
|
||||
Scan For Language='English' AND !translated
|
||||
*!* ?oGt.translate("ro","en",cuvant)
|
||||
lcPhrase = ALLTRIM(phrase)
|
||||
IF RIGHT(lcPhrase,1) = '*'
|
||||
lcPhrase = LEFT(lcPhrase, LEN(lcPhrase) - 1)
|
||||
ENDIF
|
||||
lcTranslated = oGt.translate("ro","en",lcPhrase)
|
||||
IF !EMPTY(lcTranslated)
|
||||
Replace phrase With lcTranslated , translated WITH .T.
|
||||
ENDIF
|
||||
ENDSCAN
|
||||
|
||||
Select locale
|
||||
Browse
|
||||
Define Class ugt As Custom
|
||||
* apiUrl = "http://translate.google.com/translate_t?&"+"hl=en&"+"ie=UTF8"
|
||||
apiUrl = "http://translate.google.com/translate_t?"
|
||||
*!* apiStartTags = "<"+"div id=result_box dir=ltr>"
|
||||
apiStartTags = [<div id=result_box dir="ltr">]
|
||||
apiEndTags = "<"+"/div>"
|
||||
Function translate(lcFrom,lcTo,lcText)
|
||||
Local lcHttp As MSXML2.XMLHTTP
|
||||
Local lcRequest As String
|
||||
lcRequest = This.apiUrl+"langpair="+This.urlEncode(lcFrom+"|"+lcTo)+"&"+"text="+This.urlEncode(lcText)
|
||||
lcHttp = Createobject("MSXML2.XMLHTTP")
|
||||
*!-- lcHttp.open("GET",this.apiUrl,.f.)
|
||||
lcHttp.Open("GET",lcRequest,.F.)
|
||||
lcHttp.Send()
|
||||
*!* DEBUG
|
||||
*!* SUSPEND
|
||||
If lcHttp.Status == 200
|
||||
lcText = Strextract(lcHttp.responseText,This.apiStartTags,This.apiEndTags)
|
||||
Endif
|
||||
Return lcText
|
||||
Endfunc
|
||||
|
||||
Function urlEncode
|
||||
Parameters tcValue, llNoPlus
|
||||
Local lcResult, lcChar, lnSize, lnX
|
||||
|
||||
*** Do it in VFP Code
|
||||
lcResult=""
|
||||
|
||||
For lnX=1 To Len(tcValue)
|
||||
lcChar = Substr(tcValue,lnX,1)
|
||||
If Atc(lcChar,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") > 0
|
||||
lcResult=lcResult + lcChar
|
||||
Loop
|
||||
Endif
|
||||
If lcChar=" " And !llNoPlus
|
||||
lcResult = lcResult + "+"
|
||||
Loop
|
||||
Endif
|
||||
*** Convert others to Hex equivalents
|
||||
lcResult = lcResult + "%" + Right(Transform(Asc(lcChar),"@0"),2)
|
||||
Endfor
|
||||
|
||||
Return lcResult
|
||||
Endfunc
|
||||
Enddefine
|
||||
|
||||
Reference in New Issue
Block a user