BING Desktop Translator using C# and VB.NET

Posted by: Shoban Kumar , on 7/22/2009, in Category WinForms & WinRT
Views: 121053
Abstract: In this article we will see how we can create a simple Desktop Translator which uses the Bing Translator API.
BING Desktop Translator using C# and VB.NET
 
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

If you liked the article,  Subscribe to the RSS Feed or Subscribe Via Email
 
ShobanKumar, is a 23 year old Client App Dev MVP from Trivandrum mainly working on ASP, ASP.NET, VB, VB.NET and PHP. You can also find him blogging at www.crankup.net and www.codegeeks.net. Follow him on twitter @shobankr 
Give a +1 to this article if you think it was well written. Thanks!
Recommended Articles
ShobanKumar, Client App Dev MVP, primarily works on ASP, ASP.NET, VB, VB.NET and PHP. You can also find him blogging at www.codegeeks.net and www.allaboutmoss.com. Follow him on twitter @shobankr


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by girish on Monday, September 21, 2009 7:47 AM
how to use it for hindi to english translation.
Comment posted by yosiasz on Tuesday, November 17, 2009 1:31 PM
very nice stuff here! Why do I get the following
Error   1   The type or namespace name 'TranslatorService' could not be found (are you missing a using directive or an assembly reference?)   

Thanks!
Comment posted by Shoban Kumar on Thursday, November 19, 2009 10:06 AM
@Girish Bing/Microsoft Translator does not support Hindi to English Translation. Please check : http://www.microsofttranslator.com/

@Yosuasz Make sure you did the Step 3 right :)
Comment posted by yosiasz on Thursday, November 19, 2009 11:49 AM
Shoban, thanks for the response! Step 3??? A button will solve that problem ? :O) By the way I will be using this to create an ASSEMBLY in SQL so that we can use it to translate data from table rows. I have it working for GoogleTranslate but I am stuck with this one.

Comment posted by yosiasz on Thursday, November 19, 2009 3:02 PM
Shoban, thanks for the response! Step 3??? A button will solve that problem ? :O) By the way I will be using this to create an ASSEMBLY in SQL so that we can use it to translate data from table rows. I have it working for GoogleTranslate but I am stuck with this one.

Comment posted by Shoban Kumar on Monday, November 23, 2009 12:39 PM
@Yosuasz Sorry it was a mistake ;-) It should be step 4
Comment posted by PW on Thursday, March 18, 2010 11:17 AM
You call new TranslatorService.LanguageServiceClient() twice ... intentional?
Comment posted by PW on Thursday, March 18, 2010 12:48 PM
You call new TranslatorService.LanguageServiceClient() twice ... intentional?
Comment posted by Shoban Kumar on Thursday, March 18, 2010 12:56 PM
@PW
Thanks for pointing out that ;-) It was a mistake. Calling once is enough.
Comment posted by Hector Hugo Alpizar Cesena on Wednesday, May 26, 2010 12:59 PM
I'm trying to deploy this sample but I couldn't not access to LanguageServiceClient class through the TranslatorService library. I don't if problem is becuase I'm working with .NET 3.0 Framework.
Comment posted by ankit on Sunday, August 8, 2010 12:02 AM
sir it is not working ........it is not creating any type of error but it is not generating any output.........
Comment posted by klopske on Friday, October 1, 2010 12:34 PM
It didn't work, but adding:

    "BasicHttpBinding_LanguageService"  

between "()" in this line:

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

made it work for me.

Thanks!
Comment posted by GAMA on Sunday, December 12, 2010 7:22 PM
IT'S NOT WORKING. PLS HELP ME. Message Display "Object Reference not set to an instant of an object" . Pls help me.
Comment posted by Prakash Kaur on Tuesday, March 20, 2012 6:53 AM
Wow it is great
now How can use this for other Indian language>
Comment posted by majd on Thursday, June 28, 2012 2:27 AM
hi
how i can create an AppID for Desktop Translator

"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." ?????????????????

Comment posted by Asif on Saturday, July 7, 2012 4:04 AM
why it doenst support malayalam and hindi?
Comment posted by WELruben on Wednesday, December 12, 2012 2:34 PM
there is a problem with my program , when I type something in the textbox translate.from and click the button there emerge a error : A endpoint configuration part contract translator.languagesevice can't load ...
Comment posted by Mayank Sharma on Saturday, December 15, 2012 9:18 AM
sir here are only two id are available primary account key ,customer id
and there is no app id available in my account how i can get a appid
please help me
Comment posted by Mayank Sharma on Saturday, December 15, 2012 9:24 AM
Hey WELruben you have to check your app.config file there are two end points are available..
remove the second end point
it looks like


<endpoint address="http://api.microsofttranslator.com/V1/soap.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LanguageService"
                contract="TranslatorService.LanguageService" name="BasicHttpBinding_LanguageService1" />
Comment posted by WELruben on Tuesday, December 18, 2012 2:31 PM
thank you very much.
The program works but , a can't define a appid. When a make a appid there coms a secret code en a client ID ?
how can I get a APP ID ?

Ruben,
Comment posted by Guna on Sunday, January 13, 2013 8:27 PM
I too have the same problem, where to get the app id?
Comment posted by Michael Azzar on Monday, January 28, 2013 1:40 PM
You are more than wonderful
Comment posted by Sam on Thursday, February 21, 2013 10:48 PM
Thanks Shoban Kumar.. That helped a lot :)
Comment posted by Igor on Monday, June 24, 2013 11:10 PM
thanks
Comment posted by pallavi on Friday, August 23, 2013 1:29 PM
hi,
   your test code is very nice but i want without internet connection translation code, please can you help me urgtly.....

    if you any idea so please tell me.....
-Pallavi
Comment posted by Aitazaz Khan on Wednesday, April 2, 2014 5:38 AM
bro i have an error
An endpoint configuration section for contract
Translationservice.languageservice could not be loaded because more than one endpoint configuration for that contract was found please indicate the preffered end point configuration section by name
Comment posted by Aitazaz Khan on Wednesday, April 2, 2014 5:52 AM
Ok bro problem solve you made my day its working perfectly now
Comment posted by Jie Fu on Sunday, April 27, 2014 8:36 AM
ShobanKumar, i think this is very cool but i'm getting an error "Invalid appId"
Parameter name: appId.
I already signed up here https://datamarket.azure.com/developer/applications
and got my client id and secret code as well as the application account keys but nothing of them won't work, I'm lost I need your help buddy.
Comment posted by ´sergio rezende on Wednesday, May 28, 2014 5:55 PM
hi there! getting the same error message:

Translationservice.languageservice could not be loaded because more than one endpoint configuration for that contract was found please indicate the preffered end point configuration section by name .

I´ve already signed up on windows azure marketplace and i registered as well my app e use that key into my desktop app. what am i doind wrong ? please, help me!
Comment posted by Amir on Saturday, July 5, 2014 6:33 AM
hi shobankr
Your Gtalk autoreply is great working fine.Do u have autoreply for Facebook in vb.net
plz then submit to  my Email id
Comment posted by galih suseno on Thursday, October 23, 2014 3:51 AM
hello mr.Shoban Kumar

i cannot get APPId, i just have a Primary Account key and customer ID, how can i get App ID,, help me please

Thank you

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel