Christian Heilmann

You are currently browsing the Christian Heilmann blog archives for March, 2008.

Archive for March, 2008

Making twitter multilingual with a hack of the Google Translation API

Monday, March 31st, 2008

After helping to fix the Yahoo search result pages with the correct language attributes to make them accessible for screen reader users I was wondering how this could be done with user generated content. The easiest option of course would be to ask the user to provide the right language in the profile, but if you are bilingual like me you actually write in different languages. The other option would be to offer me as the user to pick the language when I type it, which is annoying.

I then stumbled across Google’s Ajax Translation API and thought it should be very easy to marry it with for example the JSON output of the twitter API to add the correct lang attributes on the fly.

Alas, this was not as easy as I thought. On the surface it is very easy to use Google’s API to tell me what language a certain text is likely to be:

var text = “¿Dónde está el baño?”;
google.language.detect(text, function(result) {
if (!result.error) {
var language = ‘unknown’;
for (l in google.language.Languages) {
if (google.language.Languages[l] result.language) {
language = l;

var container = document.getElementById("detection");
container.innerHTML = text + " is: " + language + "";


However, if you want to use this in a loop you are out of luck. The google.language.detect method fires off an internal XHR call and the result set only gives you an error code, the confidence level, a isReliable boolean and the language code. This is a lot but there is no way to tell the function that gets the results which text was analyzed. It would be great if the API repeated the text or at least allowed you to set a unique ID for the current XHR request.

As Ajax requests return in random order, there is no way of telling which result works for which text, so I was stuck.

Enter Firebug. Analyzing the requests going through I realized there is a REST URL being called by the internal methods of google.language. In the case of translation this is:{CALLBACK_METHOD}&context={NUMBER}&q={URL_ENCODED_TEXT}&key=notsupplied&v=1.0

You can use the number and an own callback method to create SCRIPT nodes in the document getting these results back. The return call is:

CALLBACK_METHOD(‘NUMBER’,{“language” : “es”,”isReliable” : true,”confidence” : 0.24716422},200,null,200)

However, as I am already using PHP to pull information from another service, I ended up using curl for the whole proof of concept to make twitter speak in natural language:

    // curl the twitter feed
    $url = ‘’;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $twitterdata = curl_exec($ch);
    // get all the descriptions
    preg_match_all(“/([^<]+)/msi”, $twitterdata,$descs);
    // skip the main feed description
    foreach($descs[1] as $key=>$d){

    // assemble REST call and curl the result
    $url = ‘’ .
    ‘feedresult&context=’ . $key . ‘&q=’ . urlencode($d) .
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $langcode = curl_exec($ch);
    // get the language
    // write out the list item
    echo ‘

  • ‘.$d.’
  • ‘;


Check out the result: Public twitter feed with natural language support

I will do some pure JavaScript solutions soon, too. This could be a great chance to make UGC a lot more accessible.

Thanks to Mark Thomas and Tim Huegdon for bouncing off ideas about how to work around the XHR issue.

AjaxWorld East – Cold weather, Arctic Snowcruisers and a shift in perception

Thursday, March 27th, 2008

I am just sitting at the airport in Montréal, waiting for the delayed flight to arrive and get me back to New York City to get back to London. I’ve spent the last few days first in New York to speak at the AjaxWorld East conference, then go to Montréal, Canada to speak at the Coder’s Saturday and give a two presentation workshop at Nurun. Suffice to say, I am pretty bombed out, but this is a good chance to jot down my experiences during this trip. Let’s start with AjaxWorld.

The audience

The AjaxWorld conference was a bit of a surprise to me. Judging by the price of a ticket and the web site explaining all the other presentations I had braced myself to stand in front of a large room full of suits that needed to go to the conference rather than wanting to go. Turns out I was wrong. The audience was a mixed crowd of company owners, project managers, designers and developers and everybody was very involved and interested. I’ve met a lot of companies selling developer tools like frameworks and IDEs, a few implementing companies (including the lovely people from the food network who took me out for dinner for a real Italian NYC style) and really surprising edge developers like someone who ran software that controls geostationary satellites! I got a lot of interesting questions and feedback and I am happy to have met everybody there.

The location

The conference took place in the Roosevelt Hotel, located a block away from New York’s Grand Central Station. The hotel is a 1920s affair full of charm and grandeur of a bigone aera. You entered the place and felt like you are in a Hercule Poirot episode. However, for a tech conference this size it was not a great choice. For starters there was no internet connection that was either affordable or stable. Even the $24/day room connection went up and down like a roller coaster. This meant that I was driven to the bagel place (Cosi) on the other side of the street a lot as they had free Wi-fi (I am sure they made a killing these few days).

As for presentation facilities there was the main presentation hall which was a ball-room with really high ceilings reserved for sponsor talks and the keynote. This one easily allowed for all attendees to fit in, but was excruciatingly cold. All the other presentations took place in smaller meeting rooms not quite big enough to hold all interested delegates. The projectors were put in between rows of chairs which made it tricky for you to reach the screen and from time to time attendees would bump against them.

The hotel itself is also grossly overpriced for the comfort the rooms offer. My hotel in Montréal was about a third of the price per room per night, ultra-modern and had free connectivity, a fax and a safe in each room and came with complimentary breakfast. OK, it is New York city and the Roosevelt was built in the 20s, but a fleecing is a fleecing, no matter how your dress it up.

The organization and coverage

Apart from that, the hotel had a cozy atmosphere in the bar and the organizers did their best to keep everything in check. They did a splendid job filming the whole event and live-streaming parts of it. When you needed help, they were immediately there to help you out, something that is quite an uncommon event in NYC. There were more than enough handouts of the current schedules, signs were put up everywhere that you needed and every delegate got a free book on Ajax with the massive badge telling others who that person is and what he or she does. I felt pretty well looked after and was easily convinced to deliver an extra presentation in place of another presenter who had missed his flight.

The only thing I didn’t like too much is the amount of parallel presentations. I missed a lot of things I wanted to see, but couldn’t because I can’t split myself in two. Clever companies made sure that they sent several people there to allow for full coverage.

My presentations

My first presentation was a gap-filler for a speaker that didn’t show up and I wrote it a day before. I talked about the opportunity we have right now to use Flash to deliver rich media content on web sites and control the experience with JavaScript provided that we get a proper API. I got really interested in that lately, working with great people like Aral Balkan, Niqui Merret and Steve Webster. As examples I showed how SWFObject allows you to progressively enhance HTML to contain Flash, how the YUI image uploader allows you to batch upload files using Flash and how the YouTube API allows you to control online video with JavasScript.

My main and planned presentation was about architecting JavaScript for large applications using Event Driven Design showing off Yahoo Maps and Eurosport as examples. The unexpected bit of the presentation was that I explained it using the Antarctic Snowcruiser as an analogy.

The Antarctic Snowcruiser was a massive vehicle built in 1937 to explore Antarctica. The task the cruiser had to fulfill was amazingly problematic – it was to host a crew of 5 and keep them safe from the terrible cold for a year to cross 5000 miles of hostile environment. The cruiser was an absolute marvel of technology and its inventors thought up amazingly clever solutions to the problems they anticipated, including the possibility to retract the wheels into the body of the cruiser to overcome crevasses and to re-use the engine heat to keep the crew from freezing to death. The only thing they forgot to plan for was traction and when the cruiser arrived in Antarctica its wheels spun uselessly and the engine overheated almost immediately. The cruiser got abandoned and was found 20 years later encased in ice. Now it is unknown where it went as the piece of ice it was last seen on broke off and got dragged out to sea.

This was my example how we build applications – we assume a lot and over-engineer on the server side without realizing that most of the application work will be done by a browser in an to us unknown environment. I wanted to inspire people to consider the usability and restrictions of web applications before making assumptions that everything will work and that we can predict the environment our apps run in.

Both presentations were packed and I got good feedback, I’d be interested in more from people that went there and I am looking forward to seeing the videos.

Other presentations

I didn’t see many other presentations, but here is what I got: Douglas Crockford’s Keynote was a stark reminder how broken the technologies we use to create web applications really are, showed security flaws and ideas as to how we can try to fix these. Caja was mentioned along with adSafe and Douglas explained his idea of vats to secure the web. There was more and more detail published on his blog the last few days, so make sure to check there.

In terms of security, there was a full-on attack vector talk by
Danny Allan of Watchfire which showed exactly how far an unrestricted scripting injection will get attackers. It is pretty easy to disregard XSS as a banal penetration of your site but this presentation showed how a fully patched new Firefox running on a windows machine with firewall and up-to-date virus software can be accessed with malicious JavaScript and get all kind of passwords and deeper access using a mix of phishing and social engineering.

The IBM people involved in the Dojo framework showed off the internationalization and accessibility options of Dojo in a joint presentation and I was very impressed as to how far the framework embraced ARIA and how much information was given on how to do both i18n and a10y with usability in mind. Great work!

I’ve spent a lot of time with the people who build qooxdoo, a widget framework exclusively written in JavaScript. Their presentation showed what the framework is and how it works cross-browser. They also showed the very impressive performance of the widgets and how they can be skinned. The really cool stuff of qooxdoo is still in the making though and I will make sure that we watch the guys more closely and reveal some of the clever tricks they use to boost performance and build application code cleverly using a Python build script.

The last presentation I’ve seen was introducing ways to build iPhone applications that have the native look and feel and it was more or less a re-hash of the developer guidelines given out by Apple mixed with an introduction to iUI. I was not at all inspired by the talk which is amazing as iPhone is a really nice platform and highly interesting at the moment.

Summary and learnings

All in all it was well worth it going to the conference. The mix of presentations and topics covered was well done and I myself realized that it is high time we stop advocating web standards as a technical solution. Web standards are there to ensure maintainability and predictability but in the enterprise world we are already one step further and technologies like Flex, Silverlight and Comet are what need our close attention to ensure that we have predictable and maintainable solutions in these as well. Douglas’ view as the browser model as being broken can be considered as too strong a message, but I realized that a lot of the things end users expect these days are just not possible with the HTML/CSS/JS trinity we keep preaching about. This does not mean standards are unimportant – they are best practice in terms of implementation. Technologically we have to brace ourself to be surprised of the changes in the next year.

The struggle for web standards – my presentation for Coder’s Saturday in Montreal

Saturday, March 22nd, 2008

This is the presentation I have just given at the Coder’s Saturday in Montreal, Canada. The theme revolves around the adoption of standards and why this is important not only in a technological sense but much more necessary to appear as a professional developer. Most standards we talk about are really recommendations and we need to find convincing arguments why people should follow them or even why they are important to us.

Accessihacking Online Video – my presentation for BarCamp Brighton

Saturday, March 15th, 2008

I just finished my sesssion at BarCamp Brighton about making online video more accessible by allowing for sensible, time-based commenting which could become a poor man’s captioning in a second stage. In general it is just showing off my hack of the YouTube player using their API.

Video captioning made easy with the YouTube JavaScript API

Wednesday, March 12th, 2008

One thing that has been annoying me for ages is that no video player on the web allows you to write comments for a specific time in the video that get displayed as plain text. Viddler allows you to comment at a certain time and it appears in the video, but the benefits of time based captioning both in terms of accessibility and SEO didn’t quite transpire to any video site maintainers yet. Edit: Darn, I hadn’t looked at Viddler for a long time, it actually does this now, well done!

Google just released a JavaScript API for YouTube which makes it dead easy to control a video with JavaScript. You can start, stop and jump to a certain time of the video but more importantly – you have events firing when something happens to the player. This made it easy for me to whip up a proof of concept how time-based captioning might work as an interface. Click the screenshot to see it in action.

Screenshot of video with timed captions created with a small JavaScript

Start the video and hit the pause button to add a new caption. You can delete captions by hitting the x links and you can jump back to the section of the video by clicking the time stamp.

Check the source for how it is done. In order to make this a service, all you need to do is have a backend script that gets all the form fields and store it in a DB.