Google 真的已經占了我生活的一大半份,每天除了上Google查資料、收Mail外最常用的應該還有翻譯的功能了,可是每次都要在開瀏覽器起來真的有點麻煩,所以我就想說是不是可以用VB來寫一個利用google的翻譯功能的翻譯軟體,我覺得我已經中了Google的毒很深了,每天都一定要Google一下…XD

首先當然是在 visualstudio上拉好以下的畫面。

01.jpg  

在來就是最重要的寫程式啦!

Imports System.Net
Imports System.IO
Imports System.Web
Imports System.Text
Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox2.Text = FanYi(TextBox1.Text, "zh-TW|EN") '中翻英

    End Sub
    Public Function FanYi(ByVal Text As String, ByVal lang As String) As String
        Dim s As String
        Try
            Dim myAddress As String = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" & Text & "&langpair=" & lang
            Dim wc As New WebClient
            wc.Encoding = Encoding.UTF8
            Dim responseMsg As String = wc.DownloadString(myAddress)

            s = Regex.Match(responseMsg, """translatedText"":""([^""]*)""").Groups(1).Value
            Return s
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox2.Text = FanYi(TextBox1.Text, "EN|zh-TW") '英翻中

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox2.Text = FanYi(TextBox1.Text, "zh-TW|JA") '中翻日
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox2.Text = FanYi(TextBox1.Text, "JA|zh-TW") '日翻中
    End Sub

 End Class

如果您想自已加翻譯的語言的話,那就上Google查一下吧!

接下來就可以執行看看結果了。

02.jpg  

 

20110423_58dff425bdcc33fa8100R33mrNd7ebxl.jpg  

arrow
arrow
    全站熱搜

    is90057 發表在 痞客邦 留言(1) 人氣()