设为首页收藏本站官方微博

汉化资料 BING Desktop Translator using C# and VB.NET

[复制链接]
查看: 1731|回复: 1
打印 上一主题 下一主题

[汉化资料] BING Desktop Translator using C# and VB.NET

跳转到指定楼层
楼主
发表于 2010-6-10 11:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

BING Desktop Translator using C# and VB.NET

原文& \( y+ k; Q4 y
http://www.dotnetcurry.com/ShowArticle.aspx?ID=357&AspxAutoDetectCookieSupport=1
2 ]0 A# R9 W, q# Y8 q9 j% e
9 D5 w7 \. s0 B2 I* Z
( V9 ?# D2 R1 k. z8 n# [/ m+ ][align=justify]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.[align=justify]Let’s get started:[align=justify]Step 1: Start Visual studio and create a new Windows Forms Application[align=justify]Step 2: Add 2 TextBoxes and name them ‘txtTraslateFrom’ and ‘txtTranslatedText’ and set their ‘MultiLine’ property to ‘True’[align=justify]Step 3: Add a Button to the form and name it ‘btnTranslate’[align=justify]Step 4: Right Click the project and add a ‘Service Reference’ to http://api.microsofttranslator.com/V1/SOAP.svc with Namespace as TranslatorService[align=justify]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.[align=justify]Step 6: Add the following code to the Button’s Click EventC#& R8 Q% [+ u3 y8 W( c
private void btnTranslate_Click(object sender, EventArgs e)
2 j5 T. t5 o! i{3 U+ O; z" S5 [8 {# b
    string strTranslatedText = null;+ w1 {% r8 f; ~( j; R
        try
$ l6 I/ a; u$ L5 I: {8 p        {( I* T% U& I4 X3 s' a
         TranslatorService.LanguageServiceClient client = new TranslatorService.LanguageServiceClient();
& G2 b8 F; S% w# h- l         client = new TranslatorService.LanguageServiceClient();
5 i! y" b8 C% O6 x! l         strTranslatedText = client.Translate("your App ID", txtTraslateFrom.Text, "", "en");
: j! y! D2 V' ]) j+ C% s) _         txtTranslatedText.Text = strTranslatedText;
8 m' c9 u7 N7 m" x        }
$ i! J+ F6 w9 w7 S/ M  n% C        catch (Exception ex) * W( ?/ _0 d7 ]3 u$ j% F8 F/ T, I
        {
) y5 `- W" `- u; v0 O/ h         MessageBox.Show(ex.Message);
: z1 q4 R8 q2 h/ S1 R0 p) B9 o) I        }/ m2 s2 E$ B( Y) _" I- o8 E
}( G5 j- X/ _% k2 Y  {) g( E" ]( g
1 a3 }% f2 S0 k& ~$ j$ ~/ B
VB.NET" Y! z! d  l' e9 s: R
Private Sub btnTranslate_Click(ByVal sender As Object, ByVal e As EventArgs)
" q/ ]+ b  ]4 q2 Q2 {) D; D      Dim strTranslatedText As String = Nothing
. g. B) L: P$ ^- ?1 f0 U' g            Try" G! ?' F: u! C# o' m* X
             Dim client As New TranslatorService.LanguageServiceClient()
1 v) i2 V" e* W! f             client = New TranslatorService.LanguageServiceClient()
1 Y- f/ d$ s( ]7 I             strTranslatedText = client.Translate("your App ID", txtTraslateFrom.Text, "", "en")
" w0 ]0 O, K$ \, h8 {: I2 A             txtTranslatedText.Text = strTranslatedText3 g+ o0 }' j( Y: i( _" r! J2 Z- C
            Catch ex As Exception
( B1 R* j, }8 Z" D0 a! M             MessageBox.Show(ex.Message)/ _; U& f( c- Y
            End Try+ q9 a. s1 z" s, g0 A$ {1 _
End Sub
, m6 \! x5 u1 m . S) b1 g0 ]- ?) T! H$ I. ]
[align=justify]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).[align=justify] [align=justify]That’s it! Our desktop Bing Translator is ready. Below screenshot shows a sampe translation from German to English.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 很美好很美好 很差劲很差劲
回复

使用道具 举报

沙发
发表于 2010-6-11 22:43 | 只看该作者
似乎不支持中文.. 遗憾
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

冒险解谜游戏中文网 ChinaAVG

官方微博官方微信号小黑屋 微信玩家群  

(C) ChinaAVG 2004 - 2019 All Right Reserved. Powered by Discuz! X3.2
辽ICP备11008827号 | 桂公网安备 45010702000051号

冒险,与你同在。 冒险解谜游戏中文网ChinaAVG诞生于2004年9月9日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

快速回复 返回顶部 返回列表