Notification texts go here Contact Us Buy Now!

[VB] Using Google Translator

Visual Basic Using Google Translator
Hi mọi người, hôm nay mình chia sẽ lại bài viết dịch google trên ứng dụng và dữ liệu được lấy từ "GOOGLE TRANSLATE".

Thủ thuật này hoàn toàn đơn giản chứ không phức tạp nhé mọi người.
Nhược điểm hiện tại là chỉ dịch được ngôn ngữ VIỆT NAM sang ngôn ngữ ENGLISH thôi nhé mọi người, vì mình chưa tích hợp được list danh sách google dích trên ứng dụng nên mình đang viết tạm thế đã nhé mọi người.

FULL CODE:
Đầu tiên Imports những thư viện này vào
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System
Imports System.Net
Imports System.Text
Imports System.Web

Tiếp đó thêm một button và hai textbox như hình ảnh bên trên.
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox2.Text = (gtranslate(TextBox1.Text, "vi", "en")) 'From italian to english, of course you can change it
        TextBox2.Enabled = True
        My.Settings.translate = TextBox1.Text
    End Sub
    Public Shared Function gtranslate(ByVal inputtext As String, ByVal fromlangid As String, ByVal tolangid As String) As String
        inputtext = HttpUtility.HtmlAttributeEncode(inputtext)
        Dim step1 As New WebClient
        step1.Encoding = Encoding.UTF8
        Dim step2 As String = step1.DownloadString("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=" & tolangid & "&hl=" & fromlangid & "&dt=t&dt=bd&dj=1&source=icon&q=" & inputtext)
        Dim step3 As Newtonsoft.Json.Linq.JObject = JObject.Parse(step2)
        Dim step4 As String = step3.SelectToken("sentences[0]").SelectToken("trans").ToString()

        Return step4
    End Function

Như vậy các bạn lưu code và test thử chạy chương trình thôi :D
Các bạn thêm mục System.Web ở phần Add => Reference => Assemblies / Framework

VIDEO DEMO:

Chúc mọi người thành công với thủ thuật đơn giản này.

About the Author

Chia sẽ kiến thức và tư duy sáng tạo của bản thân mỗi ngày cho cộng đồng IT Việt Nam và Thế giới. Chia sẽ thủ thuật lập trình Csharp, Visual Basic, Python, Php, Javascript, Css, Html. Tối ưu hóa Windows, Microsoft, Facebook, Youtube, Chrome...v.v. …

5 comments

  1. good job, old program (y)
  2. k có nhiều tùy chọn khi translate trên app này, nên tích hợp nhiều ngôn ngữ khác nữa e nhé (y)
    1. Đúng r` a, chương trình này e đang viết demo chứ chưa tập trung chuyên sâu a nhé <3
  3. dịch thì ok, nhưng k có nhiều tùy chọn để dích những ngôn ngữ khác e ạh
    1. Đúng r` a, chương trình này e đang viết demo chứ chưa tập trung chuyên sâu a nhé <3
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
NextGen Digital Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...