Italian [LIBRERIA] Libreria traduttore

androidappl

Active Member
Licensed User
Longtime User
Ciao a tutti posto qua sotto un esempio di libreria traduttore usando yandex
"Basta richiedere l'api key GRATUITA" da yandex

Questo è il codice esempio:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim trad As Traduttore
    Dim webextra As WebViewExtras
    Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
   
    trad.ImpostaTraduttore ("it","en","{API KEY}","ciao come stai")

    webextra.addJavascriptInterface(WebView1, "B4A") ' per scaricare html
    Log(trad.Richiesta )
    WebView1.LoadUrl (trad.Richiesta )
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (url As String) 
    Log("Webview_finito")
        Dim Javascript As String
           Javascript="B4A.CallSub('ProcessHTML', false, document.documentElement.outerHTML)"
           Log("PageFinished: "&Javascript)
           webextra.executeJavascript(WebView1, Javascript)
       
End Sub

Sub ProcessHTML(HTML As String) 

    trad.Traduci_Testo(HTML)
    Log (trad.Testo_Tradotto)           
End Sub
 

Attachments

  • Libreria Yandex translator.zip
    2.8 KB · Views: 176
Top