March 30, 2009

Google Translation Service

I was tasked with some localization jobs. Generally our portals use resource files for all text, so localizing them mostly involves translating that content. The resource files are generally of the following form.

<?xml version="1.0" encoding="utf-8"?>  
<root>  
  <data name="some_title" xml:space="preserve">  
    <value>some value</value>  
    <comment>a comment</comment>  
  </data>  
</root>

Now most of the translations were done by hand, plugging them into google translator like a good little monkey. I, however, am not a good little monkey. Why do by hand what can be automated right?

After some quick searching, I found a few sample applications that did what I was trying to do. Unfortunately, they were dated and didn't play well with the latest version. The google translator API is open and supported for development like I had in mind (sort of), but does not play well with screen scrappers because of it's ajax data retrieval. That asynchronous data retrieve is pretty much what you latch onto for the API. Submit a request to a url, get some JSON back.

Sample INPUT
http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello%20world&langpair=en%7ciw&key=YOUR_API_KEY

Sample RESPONSE
{"responseData": {"translatedText":"세계 안부"}, "responseDetails": null, "responseStatus": 200}

Really strait forward to implement this type of request automatically. The previous apps even gave me all the language pairs I needed, so no work there either.

The only real work was, and I am ashamed to admit this, the serialization of the JSON response. Obviously this is easily done in javascript, but I needed the response in code.

Fortunately, this was also easier than I would have thought. Though a reference to a .NET AJAX library is required (System.Web.Script.Serialization from System.Web.Extensions)

// Container for data  
public class GoogleTranslation  
{  
    public ResponseData responseData { get; set; }  
    public string responseDetails { get; set; }  
    public string responseStatus { get; set; }  
}  
  
// Response  
public class ResponseData  
{  
    public string translatedText { get; set; }  
}  
  
// Serialization method  
public string GetLocalizedResult(string jsonResponse)  
{  
    JavaScriptSerializer ser = new JavaScriptSerializer();  
    GoogleTranslation trans = ser.Deserialize<GoogleTranslation>(jsonResponse);  
  
    return trans.responseData.translatedText;  
}

March 27, 2009

Object Store

A few weeks back I was having a discussion with a couple co-workers about how large scale web applications handle their database needs. Eventually, object store came up. I have certainly heard about object orientated databases before and their associated trade-offs. This almost made me write-off object storing as just a fresh buzz word built on old idea.

The structure is really trivial and requires the following columns:

Primary Indentifier (Object Key)
Search String (To aid in finding the key)
SystemType (The object type that the data serializes to)
Data (Use an image type)
CreatedOn (Date created
ModifiedOn (Date changed)

This is by no means something you should be using for just any field. It is, however, a very convenient solution to handling web config entries or other xml configurations. I would not recommend the creation of a god object housing everything and anything your site needs to know, but the creation of a site object, derived through this database table, could be very useful. Break it into components as needs and it really would shine. Especially with the destruction of all those painful web config entries.

The beauty of this is that your table can store any object and doesn't need to be updated if that object changes. One consideration would be in your code and that would be handling of missing xml nodes since you could be pulling in an older version.

MVC Storefront

Rob Conery made some pretty fundamental changes to his project and covers it all in depth.

MIX09 Presentation

Blog Tutorial

And there is also his source up on codeplex that is certainly worth taking a look at. I mean seriously, any web site that can run C#, ruby and python in a single page deserves at least a few minutes of your time.

March 16, 2009

Aviary

Found a pretty awesome web application site. Aviary has an online image editor (Phoenix), vector editor (Raven), color swatches (Toucan) and number of tutorials on how to create visually appealing logos and images. There is also a large number of upcoming applications.

Hummingbird - 3D Modeller and skinner
Roc - Music generator
Starling - Video editor
Owl - Desktop publishing layout editor
Penguin - Word processor
Pigeon - Painting simulator
Horus - Font editor
Hawk - Digital content marketplace
Crane - Custom image product creator
Eagle - A smart online application that can identify complex data about an image based on the pixel patterns (i.e. which specific camera an image originally came from)
Woodpecker - Smart image resizer using seam carving (minitool)
Tern - Terrain generator (minitool)

March 13, 2009

SQLite

While trying to play around with the cookies in firefox, I discovered that firefox uses SQLite to manage all its keys. This got me interested, what is this SQLite?

SQLite is an open source relational database that does not require a separate process to function. SQLite accomplishes this by storing data within a text file and accessing it through a common library. The applications for small projects, mobile apps, portable code, or prototyping become apparent and leave me wanting more information.

There is a full Administration Console (think SQL Server 2000 Query Analyzer). This makes working with the data much easier as it gives you the access you are probably familiar with.

I also found a C# Wrapper (includes libraries)  that can be used to manage your own SQLite database.

One of the immediate drawbacks I noticed was that it does not support multi-threading as it is limited to disc IO directly.

March 11, 2009

Nerd Diner

A new ASP.NET MVC example site was released yesterday. You can see it in action here or download it from source forge here . It was put together by, Rob Conery, Scott Hanselman, Phil Haack and Scott Gunthrie. There is also a pdf document covering the entire creation of the site. The document is available here .

The MVC web application features OpenID, Localization, RSS feeds, Mobile version and heavy use of Virtual Earth's API (It is a microsoft product after all).

More importantly, there is also some pretty extensive testing with mocking (Moq framework) and the integrate microsoft unit testing framework.

March 10, 2009

Rubber Duck Debugging

I read an interesting bit about debugging and thought it was worth sharing.

We called it the Rubber Duck method of debugging. It goes like this:

1) Beg, borrow, steal, buy, fabricate or otherwise obtain a rubber duck

(bathtub variety)

2) Place rubber duck on desk and inform it you are just going to go over

some code with it, if that's all right.

3) Explain to the duck what you code is supposed to do, and then go into

detail and explain things line by line

4) At some point you will tell the duck what you are doing next and then

realize that that is not in fact what you are actually doing. The duck

will sit there serenely, happy in the knowledge that it has helped you

on your way.

Works every time. Actually, if you don't have a rubber duck you could at

a pinch ask a fellow programmer or engineer to sit in.

Andy

What I find interesting about this method is that I have done the same thing countless times. I will be telling my wife about my day and some problem I was having or explaining what I am working on to a friend and get one of those moments where describing the problem provides the solution.

Programming is fun.

 
Copyright © CodeCuriosity | Theme by BloggerThemes & frostpress | Sponsored by BB Blogging