Introduction
Somebody on Codeacademy wanted a little help building a dictionary application for Windows 8. As a matter of fact, online dictionary/translator function in similar ways. Since I already worked on such functionality, I thought I would try to do it again, let's go!
1. Check online translation services
Nowadays, all online translation services seem to require a key for API use. Since Google Translate became paid only, Bing seems the best free option at the moment.
2. How the BING Translator API works...
It's much more difficult now that appID no longer works.
Resources:
- Wang Pidong's blog: How to use new Bing translator API.
- MSDN blog: Bing Translator API, getting started.
- MSDN Microsoft Translator: Obtaining an access token.
- MSDN documentation on the protocol: HTTP interface in C#
- Microsoft Bing Translator Language Codes and Names: [1], [2].
Basically you want to copy the C# code from steps 3 & 4, to create classes and functions that will handle the http stuff and deserialisation (JSON and raw string) for you.
Since we're using the WPF template for the project, you will probably need to add references to:
Since we're using the WPF template for the project, you will probably need to add references to:
- System.Configuration
- System.Runtime.Serialization
- System.Net
- System.Web
3. Verify the registration process
The registration process for the service is a bit painful. You must have something like this in your Azure Marketplace account for it to work :
Notice the two rows for both Bing Search API & Microsoft Translator.
4. Build a WPF interface
If we want to get fancy we can create to ComboBox controls databounds to the languages lists (checks links in section 2.5).
5. Implement custom configuration
Obviously, I can't give out my personal Bing keys. You will have to fill both the ClienID and the ClientSecret in exe.config.
Conclusion
You will find the sample application at WPFOnlineTranslator. You can also download the source code on the code project. Have fun! =)