A long time ago, I wrote a blog post about how to translate text in C# using Google Translate. Since then, an official AJAX API has been released, which is a much better solution. Reading the comments of the blog post indicates that the code was broken quite quickly!
We must remember to add a valid referrer when making the actual call!
This means we need to have some C# objects that we can use to deserialize the JSON returned from Google. I’m using a generic class called GoogleAjaxResponse, with T being the specific class I want the JSON to be deserialized to.
To make the actual call, we can use the HttpWebRequest and HttpWebResponse classes.
Doing a simple test, I translate “Hello world” from English to Danish, and I can see that it works like a charm.