Introduction
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’ and ComboBox (cmbfrom and cmbto)
Step 4:Right Click the project and add a ‘Service Reference’ to
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
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
TranslatorMode.ModeFrom from = (TranslatorMode.ModeFrom)Enum.Parse(typeof(TranslatorMode.ModeFrom), cmbfrom.SelectedItem.ToString());
TranslatorMode.ModeTo to = (TranslatorMode.ModeTo)Enum.Parse(typeof(TranslatorMode.ModeTo), cmbto.SelectedItem.ToString());
//
//
//
TranslatorMode.SetTranslatorMode(from, to);
TranslatorService.LanguageServiceClient Client = new TranslatorService.LanguageServiceClient();
Client = new TranslatorService.LanguageServiceClient();
translatedText = Client.Translate("Your App ID",
this.txtTraslateFrom.Text,
TranslatorMode.GetModeFrom(),
TranslatorMode.GetModeTo());
this.txtTranslatedText.Text = translatedText;
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.
This attachment is hidden for guests. Please log in or register to see it.