zoukankan      html  css  js  c++  java
  • 转【文件翻译】

    In this article we will see how we can create a simple Desktop Translator which uses the Bing Translator API. Next time when you want to translate a text, you do not have to open a new web browser and head to Bing or Google Translator. Just use this simple Translator I demonstrate here.

    Let’s get started:

    Step 1: Start Visual studio and create a new Windows Forms Application

    Step 2: Add 2 TextBoxes and name them ‘txtTraslateFrom’ and ‘txtTranslatedText’ and set their ‘MultiLine’ property to ‘True’

    Step 3: Add a Button to the form and name it ‘btnTranslate’

    Step 4: Right Click the project and add a ‘Service Reference’ to http://api.microsofttranslator.com/V1/SOAP.svc with Namespace as TranslatorService

    Step 5: To use Bing Translator Web Service you will need an AppID. Go to http://www.bing.com/developer and create a new AppID for our Desktop Translator.

    Step 6: Add the following code to the Button’s Click Event

    C#

    private void btnTranslate_Click(object sender, EventArgs e)

    {

    string strTranslatedText = null;

    try

            {

             TranslatorService.LanguageServiceClient client = new TranslatorService.LanguageServiceClient();

             client = new TranslatorService.LanguageServiceClient();

             strTranslatedText = client.Translate("your App ID", txtTraslateFrom.Text, "", "en");

             txtTranslatedText.Text = strTranslatedText;

            }

    catch (Exception ex)

            {

             MessageBox.Show(ex.Message);

            }

    }

    VB.NET

    Private Sub btnTranslate_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim strTranslatedText As String = Nothing

    Try

    Dim client As New TranslatorService.LanguageServiceClient()

                 client = New TranslatorService.LanguageServiceClient()

                 strTranslatedText = client.Translate("your App ID", txtTraslateFrom.Text, "", "en")

                 txtTranslatedText.Text = strTranslatedText

    Catch ex As Exception

                 MessageBox.Show(ex.Message)

    End Try

    End Sub

    The ‘Translate’ method takes in 4 parameters - ‘appid, text, from and to’.  In the above code we are calling the Translate method with the AppID we created in Step 5 and also passing the Text from Textbox. We pass an empty string in the ‘to’ parameter so that Bing detects the language automatically. We also set the output language to ‘en’ (English).

    That’s it! Our desktop Bing Translator is ready. Below screenshot shows a sampe translation from German to English.

    BingTranslator

    The entire source code of this article can be downloaded over here

  • 相关阅读:
    Android 图片圆角、图片圆形【转载:https://github.com/SheHuan/NiceImageView】
    fragment中嵌套listview,切换时数据出现重复加载
    fragment中嵌套listview,切换时数据出现重复加载
    Android让View的显示超出父容器
    ZooKeeper
    Redis
    kafka
    性能优化一
    RK Android7.1 禁用 USB触摸
    RK Android7.1 使用POWER按键才能开机
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/2017653.html
Copyright © 2011-2022 走看看