اذهب الي المحتوي
أوفيسنا

الردود الموصى بها

قام بنشر

انشئ مديول جديد و الصق فيه الشفرة التالية

Public Function Translate(strInput As String, strFromSourceLanguage As String, strToTargetLanguage As String) As String
On Error GoTo errorhandle
Dim strURL As String
Dim objHTTP As Object
Dim objHTML As Object
Dim objDivs As Object, objDiv As Object
Dim strTranslated As String

strURL = "https://translate.google.com/m?hl=" & strFromSourceLanguage & _
    "&sl=" & strFromSourceLanguage & _
    "&tl=" & strToTargetLanguage & _
    "&ie=UTF-8&prev=_m&q=" & EncodeQP2(strInput)

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", strURL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.Send ""

Set objHTML = CreateObject("htmlfile")
With objHTML
    .Open
    .Write objHTTP.ResponseText
    .Close
End With

Set objDivs = objHTML.getElementsByTagName("div")

For Each objDiv In objDivs

    If objDiv.className = "t0" Then
        strTranslated = objDiv.innerText
        Translate = strTranslated
    End If

Next objDiv
Set objHTML = Nothing
Set objHTTP = Nothing
errorhandleexit:
        Exit Function
errorhandle:
        MsgBox Err.Description
        Resume errorhandleexit

End Function

Function EncodeQP2(s As String) As String
    Dim i As Long
    Dim p1 As Long
    Dim p2 As Long
    Dim r As String
    Dim n As Long
    For i = 1 To Len(s)
        n = AscW(Mid(s, i, 1))
        If n < 128 Then
            r = r & "%" & Hex(n)
        ElseIf n < 2048 Then
            p1 = n \ 64
            r = r & "%" & Hex(p1 + 192)
            p2 = n Mod 64
            r = r & "%" & Hex(p2 + 128)
        Else
           
        End If
    Next i
    EncodeQP2 = r
End Function

و في حصل الاستعلام او النموذج او اي مكان ضع التالي

Translate([TextBox1], "auto", "en")

 

  • Like 3
قام بنشر

أعتقد أنه لابد من وجود اتصال انترنت ، لأن الكود يستدعي سيرفر ترجمة جوجل.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information