Anyone used Google translate from PB using webgadget?

Just starting out? Need help? Post your questions and find answers here.
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Anyone used Google translate from PB using webgadget?

Post by ricardo »

Hi,

I want to get a text and get translated by using Google translate, but not the API, but from pasting in the webgadget and reading the translated text.

Anyone has done anything yet or can point me in the right direction?

Best Regards
ARGENTINA WORLD CHAMPION
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Anyone used Google translate from PB using webgadget?

Post by IdeasVacuum »

On Windows?

I haven't tried Google Translate in the Web Gadget, but to get it to work, you will possibly need to tweak the registry:

Code: Select all

;===== Registry: temp setting to optimise web gadget =====
Global     sglpValueName.s = GetFilePart(ProgramFilename())
Global          lglpData.l = 11001
Global lglpdwDisposition.l
Global       igphkResult.i

If RegCreateKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #Null, #REG_OPTION_VOLATILE, #KEY_ALL_ACCESS, #Null, @igphkResult, @lglpdwDisposition) = #ERROR_SUCCESS
    RegSetValueEx_(igphkResult, sglpValueName, 0, #REG_DWORD, @lglpData, SizeOf(LONG))
      RegCloseKey_(igphkResult)
EndIf
[/size]
and if required:

Code: Select all

;Registry: temp setting to optimise web gadget: remove
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #KEY_SET_VALUE, @igphkResult) = #ERROR_SUCCESS

       RegDeleteValue_(igphkResult, sglpValueName)
          RegCloseKey_(igphkResult)
EndIf
[/size]
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Anyone used Google translate from PB using webgadget?

Post by ricardo »

IdeasVacuum wrote:On Windows?

I haven't tried Google Translate in the Web Gadget, but to get it to work, you will possibly need to tweak the registry:

Code: Select all

;===== Registry: temp setting to optimise web gadget =====
Global     sglpValueName.s = GetFilePart(ProgramFilename())
Global          lglpData.l = 11001
Global lglpdwDisposition.l
Global       igphkResult.i

If RegCreateKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #Null, #REG_OPTION_VOLATILE, #KEY_ALL_ACCESS, #Null, @igphkResult, @lglpdwDisposition) = #ERROR_SUCCESS
    RegSetValueEx_(igphkResult, sglpValueName, 0, #REG_DWORD, @lglpData, SizeOf(LONG))
      RegCloseKey_(igphkResult)
EndIf
[/size]
and if required:

Code: Select all

;Registry: temp setting to optimise web gadget: remove
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #KEY_SET_VALUE, @igphkResult) = #ERROR_SUCCESS

       RegDeleteValue_(igphkResult, sglpValueName)
          RegCloseKey_(igphkResult)
EndIf
[/size]
Thanks my friend!!

I resolve it :)
ARGENTINA WORLD CHAMPION
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 794
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Anyone used Google translate from PB using webgadget?

Post by Zebuddi123 »

Hi ricardo https://www.purebasic.fr/english/viewto ... 27&t=58741 google limits to 5000 characters per translation

Zebuddi. :)
malleo, caput, bang. Ego, comprehendunt in tempore
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Anyone used Google translate from PB using webgadget?

Post by ricardo »

Hello,

This is what i am trying to do. Paste or type some text into the editor gadget and in the webgadget use tranlsate google.

Its working to translate to some langguage, and im getting in the editor the translatation. Ok.

The problem:

But if i try to translate again this translation to a new language, it does not work to do this second translation... im doing domething wrong somewhere.

I know the code is a mess (im just testing and even have a lot of commented things and things that are not using anymore).

What i want to do is to be able to traslate to a language and then if i want to translate to a second, a 3rd, etc. translation

Thanks in advance

Code: Select all

DataSection 
  
  IID_IUnkown: ; 00000000-0000-0000-C000-000000000046 
  Data.l $00000000 
  Data.w $0000, $0000 
  Data.b $C0, $00, $00, $00, $00, $00, $00, $46 
  
  IID_IDispatch: ; 00020400-0000-0000-C000-000000000046 
  Data.l $00020400 
  Data.w $0000, $0000 
  Data.b $C0, $00, $00, $00, $00, $00, $00, $46 
  
  IID_IHTMLDocument2: ; 332C4425-26CB-11D0-B483-00C04FD90119 
  Data.l $332C4425 
  Data.w $26CB, $11D0 
  Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19 
  
  IID_ICustomDoc: ; 3050F3F0-98B5-11CF-BB82-00AA00BDCE0B 
  Data.l $3050F3F0 
  Data.w $98B5, $11CF 
  Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B 
  
  IID_IDocHostUIHandler: ; BD3F23C0-D43E-11CF-893B-00AA00BDCE1A 
  Data.l $BD3F23C0 
  Data.w $D43E, $11CF 
  Data.b $89, $3B, $00, $AA, $00, $BD, $CE, $1A 
  
  
EndDataSection 


#DOCHOSTUIDBLCLK_DEFAULT         = 0 
#DOCHOSTUIFLAG_OPENNEWWIN        = $20 
#DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = $100  

#DOCHOSTUIFLAG_THEME = $40000
#DOCHOSTUIFLAG_NO3DBORDER = $4 


Structure DOCHOSTUIINFO 
  cbSize.l 
  dwFlags.l 
  dwDoubleClick.l 
  *pchHostCss 
  *pchHostNS 
EndStructure 

Structure IDocHostUIHandlerImpl 
  *VTable 
  RefCount.l 
  External.IDispatch 
EndStructure 

Declare.S GetJSVariable(Gadget,Name$)
Declare SetJSVariable(Gadget,Name$,Value$)

Procedure.l IDocHostUIHandlerImpl_QueryInterface ( *that.IDocHostUIHandlerImpl, riid.l, ppObj.l ) 
  hResult.l = #E_NOINTERFACE 
  TmpUnkown.IUnknown = *that 
  If ppObj <> #Null And riid <> #Null 
    PokeL(ppObj, 0) 
    If CompareMemory(riid, ?IID_IUnkown, 16) 
      PokeL(ppObj, *that) 
      TmpUnkown\AddRef() 
      hResult = #S_OK 
    ElseIf CompareMemory(riid, ?IID_IDocHostUIHandler, 16) 
      PokeL(ppObj, *that) 
      TmpUnkown\AddRef() 
      hResult = #S_OK 
    EndIf 
  EndIf 
  ProcedureReturn hResult 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_AddRef ( *that.IDocHostUIHandlerImpl ) 
  *that\RefCount = *that\RefCount + 1 
  ProcedureReturn *that\RefCount 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_Release ( *that.IDocHostUIHandlerImpl ) 
  *that\RefCount = *that\RefCount - 1 
  RefCount.l = *that\RefCount 
  If RefCount = 0 
    If *that\External <> #Null 
      *that\External\Release() 
    EndIf  
    FreeMemory(*that) 
  EndIf 
  ProcedureReturn RefCount 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_ShowContextMenu ( *that.IDocHostUIHandlerImpl, dwID, ppt, pcmdTarget, pdispReserved ) 
  ProcedureReturn #S_FALSE 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_GetHostInfo ( *that.IDocHostUIHandlerImpl, *pInfo.DOCHOSTUIINFO ) 
  *pInfo\cbSize        = 20 
  *pInfo\dwDoubleClick = #DOCHOSTUIDBLCLK_DEFAULT 
  *pInfo\dwFlags       = #DOCHOSTUIFLAG_DIV_BLOCKDEFAULT + #DOCHOSTUIFLAG_OPENNEWWIN + #DOCHOSTUIFLAG_NO3DBORDER + #DOCHOSTUIFLAG_THEME 
  *pInfo\pchHostCss    = #Null 
  *pInfo\pchHostNS     = #Null 
  ProcedureReturn #S_OK 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_ShowUI ( *that.IDocHostUIHandlerImpl, dwID, pActiveObject, pCommandTarget, pFrame, pDoc ) 
  ProcedureReturn #S_FALSE 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_HideUI ( *that.IDocHostUIHandlerImpl ) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_UpdateUI ( *that.IDocHostUIHandlerImpl ) 
  ProcedureReturn #S_OK 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_EnableModeless ( *that.IDocHostUIHandlerImpl, fEnable) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_OnDocWindowActivate ( *that.IDocHostUIHandlerImpl, fActivate ) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_OnFrameWindowActivate ( *that.IDocHostUIHandlerImpl, fActivate ) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_ResizeBorder ( *that.IDocHostUIHandlerImpl, prcBorder, pUIWindow, fFrameWindow ) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_TranslateAccelerator ( *that.IDocHostUIHandlerImpl, lpMsg, pguidCmdGroup, nCmdID ) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_GetOptionKeyPath ( *that.IDocHostUIHandlerImpl, pchKey, dw ) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_GetDropTarget ( *that.IDocHostUIHandlerImpl, pDropTarget, ppDropTarget ) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_GetExternal ( *that.IDocHostUIHandlerImpl, ppDispatch.l ) 
  If ppDispatch <> #Null 
    PokeL(ppDispatch, *that\External) 
    If *that\External <> #Null 
      *that\External\AddRef() 
      ProcedureReturn #S_OK 
    EndIf 
  EndIf 
  ProcedureReturn #S_FALSE 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_TranslateUrl ( *that.IDocHostUIHandlerImpl, dwTranslate, pchURLIn, ppchURLOut ) 
  ProcedureReturn #S_FALSE 
EndProcedure 

Procedure.l IDocHostUIHandlerImpl_FilterDataObject ( *that.IDocHostUIHandlerImpl, pDO, ppDORet ) 
  ProcedureReturn #S_FALSE 
EndProcedure 


DataSection 
  
  IDocHostUIHandlerImplFunctionTable: 
  Data.l @IDocHostUIHandlerImpl_QueryInterface() 
  Data.l @IDocHostUIHandlerImpl_AddRef() 
  Data.l @IDocHostUIHandlerImpl_Release() 
  Data.l @IDocHostUIHandlerImpl_ShowContextMenu() 
  Data.l @IDocHostUIHandlerImpl_GetHostInfo() 
  Data.l @IDocHostUIHandlerImpl_ShowUI() 
  Data.l @IDocHostUIHandlerImpl_HideUI() 
  Data.l @IDocHostUIHandlerImpl_UpdateUI() 
  Data.l @IDocHostUIHandlerImpl_EnableModeless() 
  Data.l @IDocHostUIHandlerImpl_OnDocWindowActivate() 
  Data.l @IDocHostUIHandlerImpl_OnFrameWindowActivate() 
  Data.l @IDocHostUIHandlerImpl_ResizeBorder() 
  Data.l @IDocHostUIHandlerImpl_TranslateAccelerator() 
  Data.l @IDocHostUIHandlerImpl_GetOptionKeyPath() 
  Data.l @IDocHostUIHandlerImpl_GetDropTarget() 
  Data.l @IDocHostUIHandlerImpl_GetExternal() 
  Data.l @IDocHostUIHandlerImpl_TranslateUrl() 
  Data.l @IDocHostUIHandlerImpl_FilterDataObject() 
  
EndDataSection 


Procedure CreateDocHostUIHandler ( External.IDispatch ) 
  Protected *that.IDocHostUIHandlerImpl = AllocateMemory(SizeOf(IDocHostUIHandlerImpl)) 
  If #Null <> *that 
    *that\VTable = ?IDocHostUIHandlerImplFunctionTable 
    *that\RefCount = 1 
    If External <> #Null 
      External\AddRef() 
    EndIf 
    *that\External = External 
  EndIf 
  ProcedureReturn *that 
EndProcedure 






#DISPID_RAISEEVENT  = 100 
#DISPID_UNKNOWN     = -1 

Structure ExternalIDispatchImpl 
  *VTable 
  RefCount.l 
  *CallbackFunction 
EndStructure 

Procedure.l ExternalIDispatchImpl_QueryInterface ( *that.ExternalIDispatchImpl, riid.l, ppObj.l ) 
  hResult.l = #E_NOINTERFACE 
  TmpUnkown.IUnknown = *that 
  If ppObj <> #Null And riid <> #Null 
    PokeL(ppObj, 0) 
    If CompareMemory(riid, ?IID_IUnkown, 16) 
      PokeL(ppObj, *that) 
      TmpUnkown\AddRef() 
      hResult = #S_OK 
    ElseIf CompareMemory(riid, ?IID_IDispatch, 16) 
      PokeL(ppObj, *that) 
      TmpUnkown\AddRef() 
      hResult = #S_OK 
    EndIf 
  EndIf 
  ProcedureReturn hResult 
EndProcedure 

Procedure.l ExternalIDispatchImpl_AddRef ( *that.ExternalIDispatchImpl ) 
  *that\RefCount = *that\RefCount + 1 
  ProcedureReturn *that\RefCount 
EndProcedure 

Procedure.l ExternalIDispatchImpl_Release ( *that.ExternalIDispatchImpl ) 
  *that\RefCount = *that\RefCount - 1 
  RefCount.l = *that\RefCount 
  If RefCount = 0 
    FreeMemory(*that) 
  EndIf 
  ProcedureReturn RefCount 
EndProcedure 

Procedure.l ExternalIDispatchImpl_GetTypeInfoCount ( *that.ExternalIDispatchImpl, *pcntInfo.Long ) 
  *pcntInfo\l = 0 
  ProcedureReturn #S_OK 
EndProcedure 

Procedure.l ExternalIDispatchImpl_GetTypeInfo ( *that.ExternalIDispatchImpl, itinfo, lcid, pptinfo ) 
  ProcedureReturn #E_NOTIMPL 
EndProcedure 

Procedure.l ExternalIDispatchImpl_GetIDsOfNames ( *that.ExternalIDispatchImpl, riid, ppNames.l, cntNames.l, lcid, rgdispid.l ) 
  hResult.l = #S_OK 
  For index = 0 To cntNames - 1 
    name.S = UCase(PeekS(PeekL(ppNames + (index * 4)), -1, #PB_Unicode)) 
    If name = "RAISEEVENT" 
      PokeL(rgdispid + (index * 4), #DISPID_RAISEEVENT) 
    Else 
      PokeL(rgdispid + (index * 4), #DISPID_UNKNOWN) 
      hResult = #DISP_E_UNKNOWNNAME 
    EndIf 
  Next index 
  ProcedureReturn hResult 
EndProcedure 

Procedure.l ExternalIDispatchImpl_Invoke ( *that.ExternalIDispatchImpl, Dispid.l, riid, lcid, flags.w, *dispparams.DISPPARAMS, *result.VARIANT, *pexecpinfo, *puArgErr.Long) 
  If Dispid <> #DISPID_RAISEEVENT 
    ProcedureReturn #DISP_E_MEMBERNOTFOUND 
  EndIf  
  If 0 = #DISPATCH_METHOD & flags 
    ProcedureReturn #DISP_E_MEMBERNOTFOUND 
  EndIf  
  If *dispparams\cNamedArgs > 0 
    ProcedureReturn #DISP_E_NONAMEDARGS 
  EndIf 
  If *dispparams\cArgs <> 2 
    ProcedureReturn #DISP_E_BADPARAMCOUNT 
  EndIf 
  
  hResult.l = #S_OK 
  Dim argument.S(1) 
  Define.VARIANT TmpArg 
  For index.l = 0 To 1 
    VariantInit_(@TmpArg) 
    If VariantChangeType_(@TmpArg, *dispparams\rgvarg + ((1 - index) * SizeOf(VARIANT)), 0, #VT_BSTR) <> #S_OK 
      hResult = #DISP_E_TYPEMISMATCH 
      Break 
    EndIf 
    argument(index) = PeekS(TmpArg\bstrVal, -1, #PB_Unicode) 
    VariantClear_(@TmpArg) 
  Next index 
  If hResult <> #S_OK 
    ProcedureReturn hResult 
  EndIf 
  
  If *that\CallbackFunction <> #Null 
    CallFunctionFast(*that\CallbackFunction, @argument(0), @argument(1)) 
  EndIf 
  
  If *result <> #Null 
    VariantInit_(*result) 
    *result\vt = #VT_EMPTY 
  EndIf 
  
  ProcedureReturn #S_OK 
EndProcedure 

DataSection 
  
  ExternalIDispatchImplFunctionTable: 
  Data.l @ExternalIDispatchImpl_QueryInterface() 
  Data.l @ExternalIDispatchImpl_AddRef() 
  Data.l @ExternalIDispatchImpl_Release() 
  Data.l @ExternalIDispatchImpl_GetTypeInfoCount() 
  Data.l @ExternalIDispatchImpl_GetTypeInfo() 
  Data.l @ExternalIDispatchImpl_GetIDsOfNames() 
  Data.l @ExternalIDispatchImpl_Invoke() 
  
EndDataSection 

Procedure CreateExternalDispatch ( *CallbackFunction ) 
  Protected *that.ExternalIDispatchImpl = AllocateMemory(SizeOf(ExternalIDispatchImpl)) 
  If *that <> #Null 
    *that\VTable = ?ExternalIDispatchImplFunctionTable 
    *that\RefCount = 1 
    *that\CallbackFunction = *CallbackFunction 
  EndIf 
  ProcedureReturn *that 
EndProcedure 



    

Procedure GetIWebBrowser2 ( Gadget ) 
  Browser.IWebBrowser2 =  GetWindowLong_(GadgetID(Gadget), #GWL_USERDATA) 
  If Browser <> #Null 
    Browser\AddRef() 
  EndIf 
  ProcedureReturn Browser  
EndProcedure 

Procedure GetIHTMLDocument2( Gadget ) 
  Result.IHTMLDocument2 = #Null 
  Browser.IWebBrowser2 = GetIWebBrowser2(Gadget) 
  If Browser <> #Null 
    If Browser\get_Document(@DocumentDispatch.IDispatch) = #S_OK 
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @TmpDocument.IHTMLDocument2) = #S_OK 
        Result = TmpDocument 
      EndIf 
      DocumentDispatch\Release() 
    EndIf 
    Browser\Release()  
  EndIf 
  ProcedureReturn Result 
EndProcedure 

Procedure SetIDocHostUIHandler ( Gadget, UIHandler.IDocHostUIHandler ) 
  Result.l = #False 
  Document.IHTMLDocument2 = GetIHTMLDocument2(Gadget) 
  If Document <> #Null 
    If Document\QueryInterface(?IID_ICustomDoc, @CustomDoc.ICustomDoc) = #S_OK 
      CustomDoc\SetUIHandler(UIHandler) 
      CustomDoc\Release() 
      Result = #True 
    EndIf 
    Document\Release() 
  EndIf 
  ProcedureReturn Result 
EndProcedure 

Procedure ScriptRaiseEventCallback ( EventType.S, EventParam.S ) 
  text.S = "Type: " + Chr(34) + EventType + Chr(34) + Chr(10) 
  text = text + "Parameter: " + Chr(34) + EventParam + Chr(34) + Chr(10) 
  MessageRequester("Javascript Call", text, #PB_MessageRequester_Ok) 
EndProcedure 

;-----------------------------------------------------------

Enumeration   ; VARENUM
  #VT_EMPTY = 0
  #VT_NULL = 1
  #VT_I2 = 2
  #VT_I4 = 3
  #VT_R4 = 4
  #VT_R8 = 5
  #VT_CY = 6
  #VT_DATE = 7
  #VT_BSTR = 8
  #VT_DISPATCH = 9
  #VT_ERROR = 10
  #VT_BOOL = 11
  #VT_VARIANT = 12
  #VT_UNKNOWN = 13
  #VT_DECIMAL = 14
  #VT_I1 = 16
  #VT_UI1 = 17
  #VT_UI2 = 18
  #VT_UI4 = 19
  #VT_I8 = 20
  #VT_UI8 = 21
  #VT_INT = 22
  #VT_UINT = 23
  #VT_VOID = 24
  #VT_HRESULT = 25
  #VT_PTR = 26
  #VT_SAFEARRAY = 27
  #VT_CARRAY = 28
  #VT_USERDEFINED = 29
  #VT_LPSTR = 30
  #VT_LPWSTR = 31
  #VT_RECORD = 36
  #VT_INT_PTR = 37
  #VT_UINT_PTR = 38
  #VT_FILETIME = 64
  #VT_BLOB = 65
  #VT_STREAM = 66
  #VT_STORAGE = 67
  #VT_STREAMED_OBJECT = 68
  #VT_STORED_OBJECT = 69
  #VT_BLOB_OBJECT = 70
  #VT_CF = 71
  #VT_CLSID = 72
  #VT_VERSIONED_STREAM = 73
  #VT_BSTR_BLOB = $FFF
  #VT_VECTOR = $1000
  #VT_ARRAY = $2000
  #VT_BYREF = $4000
  #VT_RESERVED = $8000
  #VT_ILLEGAL = $FFFF
  #VT_ILLEGALMASKED = $FFF
  #VT_TYPEMASK = $FFF
EndEnumeration

#DISPATCH_METHOD = $1
#DISPATCH_PROPERTYGET = $2
#DISPATCH_PROPERTYPUT = $4
#DISPATCH_PROPERTYPUTREF = $8

DataSection
  
  IID_IHTMLDocument: ; {626FC520-A41E-11CF-A731-00A0C9082637}
  Data.l $626FC520
  Data.w $A41E, $11CF
  Data.b $A7, $31, $00, $A0, $C9, $08, $26, $37
  
  IID_NULL: ; {00000000-0000-0000-0000-000000000000}
  Data.l $00000000
  Data.w $0000, $0000
  Data.b $00, $00, $00, $00, $00, $00, $00, $00       
  
EndDataSection


Procedure.S StringFromVARIANT(*var.VARIANT)
  
  Protected Result$
  
  If VariantChangeType_(*var, *var, $2, #VT_BSTR) = #S_OK
    Result$ = PeekS(*var\bstrVal, PeekL(*var\bstrVal - 4))
    SysFreeString_(*var\bstrVal)
  Else
    Result$ = "ERROR : Cannot convert VARIANT to String!"
  EndIf
  
  ProcedureReturn Result$
EndProcedure

Procedure.S ExecuteJavaScript(Gadget.i, Function$, Arguments$, Separator$)
  
  Protected.i Result, Count, i
  Protected Result$, Message$
  Protected *dispID, *bstr_command, *Arguments
  Protected Browser.IWebBrowser2
  Protected DocumentDispatch.IDispatch, ScriptDispatch.IDispatch
  Protected Document.IHTMLDocument
  Protected *Arg.VARIANT, varResult.VARIANT
  Protected params.DISPPARAMS
  
  
  Result$ = "ERROR"
  
  Browser = GetWindowLong_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser\get_Document(@DocumentDispatch) = #S_OK
    If DocumentDispatch\QueryInterface(?IID_IHTMLDocument, @Document) = #S_OK
      If Document\get_Script(@ScriptDispatch) = #S_OK
        
        *bstr_command = SysAllocString_(Function$)
        Result = ScriptDispatch\GetIDsOfNames(?IID_NULL, @*bstr_command, 1, 0, @*dispID)
        If Result = #S_OK
          
          ; parse the arguments         
          ;
          If Trim(Arguments$) = ""
            Count = 0
            *Arguments = 0
          Else
            Count = CountString(Arguments$, Separator$)+1
            *Arguments = AllocateMemory(SizeOf(VARIANT)*Count)       
            *Arg = *Arguments
            
            For i = 1 To Count           
              *Arg\vt = #VT_BSTR
              *Arg\bstrVal = SysAllocString_(Trim(StringField(Arguments$, i, Separator$)))
              *Arg + SizeOf(VARIANT)
            Next i
          EndIf
          
          params\cArgs = Count
          params\cNamedArgs = 0
          params\rgvarg = *Arguments
          
          Result = ScriptDispatch\Invoke(*dispID, ?IID_NULL, 0, #DISPATCH_METHOD, @params, @varResult, 0, 0)
          If Result = #S_OK
            Result$ = StringFromVARIANT(@varResult)
          Else
            Message$ = Space(3000)
            FormatMessage_(#FORMAT_MESSAGE_IGNORE_INSERTS|#FORMAT_MESSAGE_FROM_SYSTEM, 0, Result, 0, @Message$, 3000, 0)         
            Result$ = "ERROR: Invoke() "+Message$           
          EndIf
          
          If *Arguments
            *Arg.VARIANT = *Arguments
            For i = 1 To Count
              SysFreeString_(*Arg\bstrVal)
              *Arg + SizeOf(VARIANT)
            Next i         
            FreeMemory(*Arguments)
          EndIf
          
        Else
          Message$ = Space(3000)
          FormatMessage_(#FORMAT_MESSAGE_IGNORE_INSERTS|#FORMAT_MESSAGE_FROM_SYSTEM, 0, Result, 0, @Message$, 3000, 0)         
          Result$ = "ERROR: GetIDsOfNames() "+Message$         
          
        EndIf
        SysFreeString_(*bstr_command)
        
        ScriptDispatch\Release()
      EndIf
      Document\Release()
    EndIf
    DocumentDispatch\Release()
  EndIf
  
  ProcedureReturn Result$
EndProcedure


Procedure.S GetJSVariable(Gadget.i, Name$)
  
  Protected Dispid.i, Result.i
  Protected Result$, Message$
  Protected *bstr_name
  Protected Browser.IWebBrowser2
  Protected DocumentDispatch.IDispatch, ScriptDispatch.IDispatch
  Protected Document.IHTMLDocument
  Protected params.DISPPARAMS
  Protected varResult.VARIANT
  
  
  Result$ = "ERROR"
  
  Browser = GetWindowLong_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser\get_Document(@DocumentDispatch) = #S_OK
    If DocumentDispatch\QueryInterface(?IID_IHTMLDocument, @Document) = #S_OK
      If Document\get_Script(@ScriptDispatch) = #S_OK
        
        *bstr_name = SysAllocString_(Name$)
        Result = ScriptDispatch\GetIDsOfNames(?IID_NULL, @*bstr_name, 1, 0, @Dispid)
        If Result = #S_OK
          
          params\cArgs = 0
          params\cNamedArgs = 0       
          
          Result = ScriptDispatch\Invoke(Dispid, ?IID_NULL, 0, #DISPATCH_PROPERTYGET, @params, @varResult, 0, 0)
          If Result = #S_OK
            Result$ = StringFromVARIANT(@varResult)
          Else
            Message$ = Space(3000)
            FormatMessage_(#FORMAT_MESSAGE_IGNORE_INSERTS|#FORMAT_MESSAGE_FROM_SYSTEM, 0, Result, 0, @Message$, 3000, 0)         
            Result$ = "ERROR: Invoke() "+Message$           
          EndIf
          
        Else
          Message$ = Space(3000)
          FormatMessage_(#FORMAT_MESSAGE_IGNORE_INSERTS|#FORMAT_MESSAGE_FROM_SYSTEM, 0, Result, 0, @Message$, 3000, 0)         
          Result$ = "ERROR: GetIDsOfNames() "+Message$         
          
        EndIf
        SysFreeString_(*bstr_name)
        
        ScriptDispatch\Release()
      EndIf
      Document\Release()
    EndIf
    DocumentDispatch\Release()
  EndIf
  
  ProcedureReturn Result$
EndProcedure

Procedure SetJSVariable(Gadget, Name$, Value$)
  
  Protected.i success, Dispid, Result, dispidNamed
  Protected *bstr_name
  Protected Browser.IWebBrowser2
  Protected DocumentDispatch.IDispatch, ScriptDispatch.IDispatch
  Protected Document.IHTMLDocument
  Protected varValue.VARIANT
  Protected params.DISPPARAMS
  
  
  
  Browser = GetWindowLong_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser\get_Document(@DocumentDispatch) = #S_OK
    If DocumentDispatch\QueryInterface(?IID_IHTMLDocument, @Document) = #S_OK
      If Document\get_Script(@ScriptDispatch) = #S_OK
        
        *bstr_name = SysAllocString_(Name$)
        Result = ScriptDispatch\GetIDsOfNames(?IID_NULL, @*bstr_name, 1, 0, @Dispid)
        If Result = #S_OK
          
          varValue\vt = #VT_BSTR
          varValue\bstrVal = SysAllocString_(Value$)
          
          dispidNamed = -3 ; #DISPID_PROPERTYPUT
          params\cArgs = 1
          params\cNamedArgs = 1
          params\rgvarg = @varValue
          params\rgdispidNamedArgs = @dispidNamed
          
          Result = ScriptDispatch\Invoke(Dispid, ?IID_NULL, 0, #DISPATCH_PROPERTYPUT, @params, 0, 0, 0)
          If Result = #S_OK
            success = 1   
          EndIf
          
          SysFreeString_(varValue\bstrVal)
          
        EndIf
        SysFreeString_(*bstr_name)
        
        ScriptDispatch\Release()
      EndIf
      Document\Release()
    EndIf
    DocumentDispatch\Release()
  EndIf
  
  ProcedureReturn success
EndProcedure

;----------------------------------------------------------------------------------------



;----------------------------------------------------------------------------------------

#PUSH_CTRL     = 0
#PUSH_ALT      = 1
#PUSH_SHIFT    = 2

DataSection
  
  ; IID_IHTMLDocument: ; {626FC520-A41E-11CF-A731-00A0C9082637}
  ; Data.l $626FC520
  ; Data.w $A41E, $11CF
  ; Data.b $A7, $31, $00, $A0, $C9, $08, $26, $37
  
  ; IID_IHTMLDocument2: ; {332C4425-26CB-11D0-B483-00C04FD90119}
  ; Data.l $332C4425
  ; Data.w $26CB, $11D0
  ; Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19
  
  IID_IHTMLDocument3: ; {3050F485-98B5-11CF-BB82-00AA00BDCE0B}
  Data.l $3050F485
  Data.w $98B5,$11CF
  Data.b $BB,$82,$00,$AA,$00,$BD,$CE,$0B
  
  IID_IHTMLDocument4: ; {3050F69A-98B5-11CF-BB82-00AA00BDCE0B}
  Data.l $3050F69A
  Data.w $98B5, $11CF
  Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
  
  IID_IHTMLDocument5: ; {3050F80C-98B5-11CF-BB82-00AA00BDCE0B}
  Data.l $3050F80C
  Data.w $98B5, $11CF
  Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
  
  IID_IHTMLElement: ; {3050F1FF-98B5-11CF-BB82-00AA00BDCE0B}
  Data.l $3050F1FF
  Data.w $98B5, $11CF
  Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
  
EndDataSection


Macro KEY_DOWN (iKey)
  keybd_event_ (iKey, 0, 0, 0)
EndMacro   

Macro KEY_UP (iKey)
  keybd_event_(iKey, 0, #KEYEVENTF_KEYUP, 0)
EndMacro   

Procedure.i WebGadget_GetHTMLDocument2 (nGadget)
  Protected oBrowser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(nGadget), #GWL_USERDATA)
  Protected oDocumentDispatch.IDispatch
  Protected oHTMLDocument.IHTMLDocument2
  Protected iBusy
  
  Repeat
    While WindowEvent(): Delay(0): Wend   
    oBrowser\get_Busy(@iBusy): Delay(10)       
  Until iBusy = #VARIANT_FALSE
  
  If oBrowser
    If oBrowser\get_document(@oDocumentDispatch) = #S_OK
      If oDocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @oHTMLDocument) = #S_OK
        oDocumentDispatch\Release()
      EndIf
    EndIf
  EndIf
  
  ProcedureReturn oHTMLDocument
EndProcedure

Procedure.i WebGadget_GetHTMLDocumentParent (nGadget)
  Protected oHTMLDocument.IHTMLDocument2 = WebGadget_GetHTMLDocument2 (nGadget)
  Protected oWindow.IHTMLWindow2
  
  If oHTMLDocument
    oHTMLDocument\get_parentWindow(@oWindow)
  EndIf
  
  oHTMLDocument\Release() 
  
  ProcedureReturn oWindow
EndProcedure

Procedure WebGadget_SetFocus (nGadget)
  Protected oWindow.IHTMLWindow2 = WebGadget_GetHTMLDocumentParent (nGadget)
  
  If oWindow   
    oWindow\focus()
    oWindow\Release()
  EndIf
EndProcedure

Procedure WebGadget_ExecScript (nGadget, sScriptCode.S, sScriptLanguage.S = "JavaScript")   
  Protected oWindow.IHTMLWindow2 = WebGadget_GetHTMLDocumentParent (nGadget)
  Protected tVariant.VARIANT
  
  If oWindow
    oWindow\execScript (sScriptCode, sScriptLanguage, @tVariant)
    oWindow\Release()
  EndIf   
EndProcedure

Procedure WebGadget_SetFocusByName (nGadget, sFieldName.S)
  Protected sScript.S
  Delay(500)
  sScript = "var elements = document.getElementsByName('"+ sFieldName + "');"
  sScript + "for (var i = 0; i < elements.length; ++i)"
  sScript + "{"
  sScript + "if (elements[i].tagName.toLowerCase() == 'input')"
  sScript + "{"
  sScript + "elements[i].focus();"
  sScript + "break;"
  sScript + "}"
  sScript + "}"
  
  WebGadget_ExecScript (nGadget, sScript)
EndProcedure

Procedure WebGadget_SetFocusByClassName (nGadget, sFieldName.S)
  Protected sScript.S
  Delay(500)
  sScript = "var elements = document.getElementsByClassName('"+ sFieldName + "');"
  sScript + "for (var i = 0; i < elements.length; ++i)"
  sScript + "{"
  sScript + "if (elements[i].tagName.toLowerCase() == 'input')"
  sScript + "{"
  sScript + "elements[i].focus();"
  sScript + "break;"
  sScript + "}"
  sScript + "}"
  
  WebGadget_ExecScript (nGadget, sScript)
EndProcedure

Procedure WebGadget_SetFocusByID (nGadget, sFieldName.S)
  Protected sScript.S
  Delay(500)
  sScript = "var elements = document.getElementById('"+ sFieldName + "');"
  sScript + "if (elements.tagName.toLowerCase() == 'input')"
  sScript + "{"
  sScript + "elements.focus();"
  sScript + "}"
  WebGadget_ExecScript (nGadget, sScript)
EndProcedure

Procedure WebGadget_SetTextByID (nGadget, sFieldName.S,text.S)
  Protected sScript.S
  Delay(500)
  sScript = "var elements = document.getElementById('"+ sFieldName + "');"
  sScript + "if (elements.tagName.toLowerCase() == 'input')"
  sScript + "{"
  sScript + "elements.focus();"
  sScript + "}"
  WebGadget_ExecScript (nGadget, sScript)
EndProcedure

Procedure WebGadget_SetTextByName (nGadget, sFieldName.S, text.S)
  Protected sScript.S
  Delay(500)
  sScript = "var elements = document.getElementsByName('"+ sFieldName + "');"
  sScript + "for (var i = 0; i < elements.length; ++i)"
  sScript + "{"
  sScript + "if (elements[i].tagName.toLowerCase() == 'input')"
  sScript + "{"
  sScript + "elements[i].focus();"
  sScript + "break;"
  sScript + "}"
  sScript + "}"
  
  WebGadget_ExecScript (nGadget, sScript)
EndProcedure

Procedure WebGadget_SetTextByClassName (nGadget, sFieldName.S, text.S)
  Protected sScript.S
  Delay(500)
  sScript = "var elements = document.getElementsByClassName('"+ sFieldName + "');"
  sScript + "for (var i = 0; i < elements.length; ++i)"
  sScript + "{"
  sScript + "if (elements[i].tagName.toLowerCase() == 'input')"
  sScript + "{"
  sScript + "elements[i].focus();"
  sScript + "break;"
  sScript + "}"
  sScript + "}"
  
  WebGadget_ExecScript (nGadget, sScript)
EndProcedure


Procedure Check_SetFocusByName (nGadget, sFieldName.S, Value$)
  Protected sScript.S
  Delay(500)
  sScript = "var elements = document.getElementsByName('"+ sFieldName + "');"
  sScript + "for (var i = 0; i < elements.length; ++i)"
  sScript + "{"
  sScript + "if (elements[i].tagName.toLowerCase() == 'input')"
  sScript + "{"
  sScript + "if {elements[i].value() == '" + Value$ + "');"
  sScript + "document.title = 'YES';"
    sScript + "break;"
  sScript + "}"
  sScript + "}"
  sScript + "}"
  
  WebGadget_ExecScript (nGadget, sScript)
EndProcedure


Procedure WebGadget_SelectLink (nGadget, index)
  Protected sScript.S
  
  sScript = "var elements = document.all.tags('a')(" + Str(index) + ");"
  sScript + "elements.focus();"
  
  
  WebGadget_ExecScript (nGadget, sScript)
EndProcedure

Procedure PushKey (iKey, iMod = 0)
  Delay(20)
  If iMod & #PUSH_CTRL
    KEY_DOWN (#VK_CONTROL)
  EndIf
  
  If iMod & #PUSH_SHIFT
    KEY_DOWN (#VK_SHIFT)
  EndIf
  
  If iMod & #PUSH_ALT
    KEY_DOWN (#VK_MENU)
  EndIf
  
  If iKey
    KEY_DOWN (iKey)
    KEY_UP (iKey)
  EndIf
  
  If iMod & #PUSH_ALT
    KEY_UP (#VK_MENU)
  EndIf
  
  If iMod & #PUSH_SHIFT
    KEY_UP (#VK_SHIFT)
  EndIf
  
  If iMod & #PUSH_CTRL
    KEY_UP (#VK_CONTROL)
  EndIf
  WindowEvent()
EndProcedure

Procedure TypeWords(xWord$)
  If GetKeyState_(#VK_CAPITAL) = 1
    ; Debug "Estaba en mayusculas"
    kMayusculas = 1
    PushKey(#VK_CAPITAL)
  Else
    ; Debug "Esta en minusculas"
    kMayusculas = 0
  EndIf
  OldLetra = 0 
  
  ; Debug ""
  ; Debug ""
  
  For i = 1 To Len(xWord$)
    Letra$ = Mid(xWord$,i,1)
    
    If Asc(Letra$) > 64 And Asc(Letra$) < 91
      Mayusculas = 1
      ; Debug Letra$
    ElseIf Asc(Letra$) > 96 And Asc(Letra$) < 123
      Mayusculas = 0
      ; Debug Letra$
    EndIf
    
    ; If GetKeyState_(#VK_CAPITAL) = 1
    ; If Mayusculas = 0
    ; PushKey(#VK_CAPITAL)
    ; EndIf
    ; Else
    ; If Mayusculas = 1
    ; PushKey(#VK_CAPITAL)
    ; EndIf
    ; EndIf
    
    If OldLetra <> Mayusculas
      ; Debug "Cambia: " + Letra$
      OldLetra = Mayusculas
      PushKey(#VK_CAPITAL)
    EndIf
    
    cccLetra$ = UCase(Letra$)
    Select cccLetra$
      Case " "
        PushKey(#VK_SPACE)
        
      Case "0"
        PushKey(#VK_0)
      Case "1"
        PushKey(#VK_1)
      Case "2"
        PushKey(#VK_2)
      Case "3"
        PushKey(#VK_3)
      Case "4"
        PushKey(#VK_4)
      Case "5"
        PushKey(#VK_5)
      Case "6"
        PushKey(#VK_6)
      Case "7"
        PushKey(#VK_7)
      Case "8"
        PushKey(#VK_8)
      Case "9"
        PushKey(#VK_9)
        
        ;----Letras
        
      Case "A"
        PushKey(#VK_A)
      Case "B"
        PushKey(#VK_B)
      Case "C"
        PushKey(#VK_C)
      Case "D"
        PushKey(#VK_D)
      Case "E"
        PushKey(#VK_E)
      Case "F"
        PushKey(#VK_F)
      Case "G"
        PushKey(#VK_G)
      Case "H"
        PushKey(#VK_H)
      Case "I"
        PushKey(#VK_I)
      Case "J"
        PushKey(#VK_J)
      Case "K"
        PushKey(#VK_K)
      Case "L"
        PushKey(#VK_L)
      Case "M"
        PushKey(#VK_M)
      Case "N"
        PushKey(#VK_N)
      Case "O"
        PushKey(#VK_O)
      Case "P"
        PushKey(#VK_P)
      Case "Q"
        PushKey(#VK_Q)
      Case "R"
        PushKey(#VK_R)
      Case "S"
        PushKey(#VK_S)
      Case "T"
        PushKey(#VK_T)
      Case "U"
        PushKey(#VK_U)
      Case "V"
        PushKey(#VK_V)
      Case "W"
        PushKey(#VK_W)
      Case "X"
        PushKey(#VK_X)
      Case "Y"
        PushKey(#VK_Y)
      Case "Z"
        PushKey(#VK_Z)
        
    EndSelect
    
  Next
  
  Delay(500)
  
EndProcedure

Structure INTERNET_PROXY_INFO1
  dwAccessType.l
  lpszProxy.l
  lpszProxyBypass.l
EndStructure

#INTERNET_OPTION_PROXY = 38

ProcedureDLL SetProxy1(Proxy.S, Port.l, flags.l=#INTERNET_OPEN_TYPE_PROXY) ; Set proxy for the current session
  ;/ Return 1 if success or 0 if fail
  
  Protected ProxyServer.S = Proxy + ":" + Str(Port)
  Protected PIInfo.INTERNET_PROXY_INFO1
  PIInfo\dwAccessType = flags
  PIInfo\lpszProxy = @ProxyServer
  PIInfo\lpszProxyBypass = @""
  If UrlMkSetSessionOption_(#INTERNET_OPTION_PROXY, @PIInfo, SizeOf(INTERNET_PROXY_INFO1), 0) = #S_OK
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure

;===== Registry: temp setting to optimise web gadget =====
Global     sglpValueName.S = GetFilePart(ProgramFilename())
Global          lglpData.l = 11001
Global lglpdwDisposition.l
Global       igphkResult.i

If RegCreateKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #Null, #REG_OPTION_VOLATILE, #KEY_ALL_ACCESS, #Null, @igphkResult, @lglpdwDisposition) = #ERROR_SUCCESS
  RegSetValueEx_(igphkResult, sglpValueName, 0, #REG_DWORD, @lglpData, SizeOf(Long))
  RegCloseKey_(igphkResult)
EndIf




#WEB_MAIN = 0

Procedure.S Traduce()
  ExecuteJavaScript(#WEB_MAIN,"eval","var traduccion1 = document.body.innerHTML","")
  HTML$ =  GetJSVariable(#WEB_MAIN,"traduccion1")
  ;Debug HTML$
  Pos = 0
  If FindString(HTML$,"translation translation",0)
    Debug "Encontro translation"
    Pos = FindString(HTML$,"translation translation",0)
    Pos = FindString(HTML$,"<span",Pos+1)
    Pos = FindString(HTML$,">",Pos+1)
    EndPos = FindString(HTML$,"<",Pos+1)
    Debug Pos
    Debug EndPos
    Debug HTML$
    Traduccion$ = Mid(HTML$,Pos+1,EndPos-Pos-1)
    Debug Traduccion$
    ProcedureReturn Traduccion$
  EndIf
  Debug "--------------------------"
EndProcedure



If OpenWindow(0, 10000, 0, 0, 0, "WebGadget",  #PB_Window_SystemMenu|#PB_Window_Maximize);|#PB_Window_Invisible) 
  CreateGadgetList(WindowID(0)) 
  WebGadget(0, 0, 0, (WindowWidth(0)+50),WindowHeight(0)-100, "about:blank") 
  HideGadget(0,1)
  EditorGadget(2,0,0,(WindowWidth(0)+50),WindowHeight(0)-100)
  
  ButtonGadget(1,50,WindowHeight(0)-50,150,25,"Aleman")
  ButtonGadget(10,250,WindowHeight(0)-50,150,25,"Frances")
  ButtonGadget(11,450,WindowHeight(0)-50,150,25,"Ingles")
  ButtonGadget(12,650,WindowHeight(0)-50,150,25,"Copy")
  ButtonGadget(14,850,WindowHeight(0)-50,150,25,"Mostrar webgadget")
  
  
  
  
  
  External.IDispatch  = CreateExternalDispatch(@ScriptRaiseEventCallback()) 
  UIHandler.IDocHostUIHandler = CreateDocHostUIHandler(External) 
  SetIDocHostUIHandler(0, UIHandler) 
  External\Release() 
  UIHandler\Release() 
  Browser.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA) 
  Browser\put_Silent(#True)
  Repeat 
    Event = WaitWindowEvent(); 
    Select Event 
      Case #PB_Event_Gadget
        Select EventGadget()  
          Case 14
            HideGadget(0,0)
            HideGadget(2,1)
          Case 1 ;//////////////////// TRADUCE A ALEMAN
            Debug "ALEMAN"
            TextoEdirtor$ = GetGadgetText(2)
            TextoaTraducir$ = URLEncoder(TextoEdirtor$)
            IdiomaDelTraductor$ = "de"
            TranslateURL$ = "https://translate.google.com/#view=home&op=translate&sl=auto&tl=" + IdiomaDelTraductor$ + "&text=" + TextoaTraducir$
            iStepCount = 0
            Debug TranslateURL$
            SetGadgetText(#WEB_MAIN,TranslateURL$)
            ; HideGadget(0,0)
            ; HideGadget(2,1)
          Case 10 
            Debug "FRANCES"
            TextoEdirtor$ = GetGadgetText(2)
            TextoaTraducir$ = URLEncoder(TextoEdirtor$)
            IdiomaDelTraductor$ = "fr"
            TranslateURL$ = "https://translate.google.com/#view=home&op=translate&sl=auto&tl=" + IdiomaDelTraductor$ + "&text=" + TextoaTraducir$
            iStepCount = 0
            Debug TranslateURL$
            SetGadgetText(#WEB_MAIN,TranslateURL$)
          Case 11
            Debug "INGLES"
            TextoEdirtor$ = GetGadgetText(2)
            TextoaTraducir$ = URLEncoder(TextoEdirtor$)
            IdiomaDelTraductor$ = "en"
            TranslateURL$ = "https://translate.google.com/#view=home&op=translate&sl=auto&tl=" + IdiomaDelTraductor$ + "&text=" + TextoaTraducir$
            iStepCount = 0
            Debug TranslateURL$
            SetGadgetText(#WEB_MAIN,TranslateURL$)
          Case 12
            
            TextoEdirtor$ = GetGadgetText(2)
            SetClipboardText(TextoEdirtor$)
          Case #WEB_MAIN
            ;Debug GetGadgetText(#WEB_MAIN)
            ;Debug "EVENT WEB"
            Select EventType()
                
                
              Case #PB_EventType_TitleChange
                ;Debug "Title Change"
                ;Debug GetGadgetItemText(#WEB_MAIN,#PB_Web_PageTitle)
              Case #PB_EventType_StatusChange
                ;Debug "Status Change"
              Case #PB_EventType_DownloadEnd                           
                iStepCount + 1
                Debug "Bajo"
                Debug "iStepCount"
                Debug iStepCount
                Select iStepCount
                  Case 2 ;---------------------------- VA A LLENAR AL FORM DE TEXTO A TRADUCIR
                    Debug "Case 2"

                    Debug "Typeo"
                    Traducido$ = Traduce()
                    SetGadgetText(2,Traducido$)
                    Debug "========= FINISH TRANSLATE"

                    iStepCount = 0
                  Case 3
                    Debug "CASE 3"

                    
                  Case 4
                    Debug "CASE 4"
                    ExecuteJavaScript(#WEB_MAIN,"eval","var traduccion = document.body.innerText","")
                    Debug  GetJSVariable(#WEB_MAIN,"traduccion")
                  Case 1
                    Debug "Case 1"


                    
                    WebGadget_SetFocus(#WEB_MAIN)
                    
                    Debug "Mostrara titulo"
                    Debug GetGadgetItemText(#WEB_MAIN,#PB_Web_PageTitle)
                    
                    Traducido$ = Traduce()
                    Debug Traducido$
 
                  Case 2:
                    Debug "Ended."

                  Case 3
                    Debug "Final"
                EndSelect
            EndSelect                   
        EndSelect
      Case #PB_Event_CloseWindow 
        Break 
    EndSelect 
  Until GetAsyncKeyState_(#VK_ESCAPE)
  
  
EndIf 


;Registry: temp setting to optimise web gadget: remove
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", 0, #KEY_SET_VALUE, @igphkResult) = #ERROR_SUCCESS
  
  RegDeleteValue_(igphkResult, sglpValueName)
  RegCloseKey_(igphkResult)
EndIf

Debug "CLOSE"


ARGENTINA WORLD CHAMPION
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Anyone used Google translate from PB using webgadget?

Post by IdeasVacuum »

Hi Ricardo

Did you ever fix your issue? It occured to me that Google silently rejects automated translation requests - so you have to send each request 2 or 3 seconds apart.

I notice that you have "text" procedures where the Text argument is never actually used?

WebGadget_SetTextByID
WebGadget_SetTextByName
WebGadget_SetTextByClassName

Edit: You may have already found this - I first translated to French, worked fine. I then translated to German, no result.

So I did a manual search of the HTML. In the "French" HTML, sure enough, found the string in French.
Then I did a manual search in the "German" HTML - and found the string in French! The Web Gadget is correctly displaying the string in German, so there is the mystery.

Edit2: If you alternate between the .com and .co.uk servers, the results are correct!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Anyone used Google translate from PB using webgadget?

Post by ricardo »

IdeasVacuum wrote:Hi Ricardo

Did you ever fix your issue? It occured to me that Google silently rejects automated translation requests - so you have to send each request 2 or 3 seconds apart.

I notice that you have "text" procedures where the Text argument is never actually used?

WebGadget_SetTextByID
WebGadget_SetTextByName
WebGadget_SetTextByClassName

Edit: You may have already found this - I first translated to French, worked fine. I then translated to German, no result.

So I did a manual search of the HTML. In the "French" HTML, sure enough, found the string in French.
Then I did a manual search in the "German" HTML - and found the string in French! The Web Gadget is correctly displaying the string in German, so there is the mystery.

Edit2: If you alternate between the .com and .co.uk servers, the results are correct!
WebGadget_SetTextByID
WebGadget_SetTextByName
WebGadget_SetTextByClassName

I used to fill forms in other codes.

Yes, Google translate is something strange... with some mysteries

Best Regards
ARGENTINA WORLD CHAMPION
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Anyone used Google translate from PB using webgadget?

Post by IdeasVacuum »

Hi Ricardo

Another discovery (probably everybody knew this except me):

If you set text on the translation page, there is a limit of 5000 characters. However, if instead you upload the text in a file, there is apparently no limit (there probably is, but I haven't hit it yet!).
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Anyone used Google translate from PB using webgadget?

Post by ricardo »

IdeasVacuum wrote:Hi Ricardo

Another discovery (probably everybody knew this except me):

If you set text on the translation page, there is a limit of 5000 characters. However, if instead you upload the text in a file, there is apparently no limit (there probably is, but I haven't hit it yet!).

Yes, i notice it sometime ago. I translate large articles without limit. But don know how to do thyid automatically.
ARGENTINA WORLD CHAMPION
Post Reply