Dr Nic

Do you write code and smile?

Do you write code and smile?

Do spend two hours on a hack to save yourself one hour of time?

Is being a great coder important to you, even if you don’t know why its important?

Do you derive a sense of pride from a few lines of code you wrote?

I thought of all these questions whilst watching a great guitar clip… he’s gone beyond learning Pachelbel’s Canon in D Major, and overlayed his own code. Underneath the hat, I’m sure he’s smiling.

His pride for his guitar work makes me happy for my coding. You?

Translation of RSS feeds a failure (part 3)

My path to spying on the Japanese wouldn’t be complete without support for translating RSS feeds. The translation needs to be performed on the feed itself before it hits the feedreader (unless you have non-Ajaxy webreaders that you can translate).

Unfortunately, Google Translate seems to ignore RSS altogether, and just redirects you back to the original RSS feed.

For example, take sample feed: http://d.hatena.ne.jp/hanazukin/rss2

Press the Spy on Japanese bookmarklet (cheat: click here for translation) and you’ll see the original RSS feed in the lower frame. Its not that its been poorly translated – Google just redirects you back to the original page instead of translating it.

Two solutions:

  1. Use a HTML -> RSS feed converter and use the direct translation url (use translate_c? instead of translate? in the url)
  2. Google Translate should add RSS feed translation. Really it cannot be more difficult than HTML translation. Add some caching (which google loves to do anyway) so its not translating each time my feed reader polls the feed, and you’re off and running.
  3. NEW – create a translator proxy that accepts RSS feed urls, converts the feed to a primitive HTML format, translate on google, convert results back to RSS feed

I prefer #2. So, if any Googlers read this blog, or if any friends of Larry & Co. are reading this blog, or if anyone remotely interested in popping over to the Googleplex to pass on a message from me, could ask the Google Translate ppl to add RSS feed support, I’d be a very very happy man.

Foreign tourists to your websites (part 2)

As a follow-up to the recent “Spy on the Japanese” post, you might want a nice set of links for your visitors to translate your page sinto their language.

But, here are your requirements (I can read your mind, I’m a doctor):

  • You know what countries visit your site, so you want to configure it yourself.
  • Since it requires Javascript to be turned on for it to work, you don’t want the links to show if the visitor doesn’t.

Solution: create the links using Javascript.

To allow translations of your blogs/websites via Google Translation, add the following inline Javascript into the sidebar. It was designed for WordPress – you may need to twiddle with the DOM elements created and/or CSS if it looks bad on your site.

The flags can be found at: http://www.famfamfam.com/lab/icons/flags/, and I’ve assumed you’ll store the png images in the /images/flags/ folder. If you store them somewhere else, change the images variable at the top of the script.

So, paste this script into your sidebar and you are saying “Aliens Welcome Here” [1].

      <script>
        // Each lang in an array: [google lang code, flag name, language name]
        // Flags available at: http://www.famfamfam.com/lab/icons/flags/
        var to_langs  = [['ja', 'jp', 'Japanese'],
                         ['de', 'de', 'German'],
                         ['es', 'es', 'Spanish']];
        var from_lang = 'en';
        var images     = '/images/flags/';

        document.write("<li id='translation'></li>");
        var liDiv = document.getElementById('translation');
        var title = document.createElement("h2");
        title.appendChild(document.createTextNode("Translation"));
        liDiv.appendChild(title);
        var ulDiv = document.createElement("ul");
        liDiv.appendChild(ulDiv);
        for (var i=0; i < to_langs.length; i++) {
          var to_lang = to_langs[i][0];
          var flag    = to_langs[i][1];
          var name    = to_langs[i][2];
          liDiv = document.createElement('li');
          ulDiv.appendChild(liDiv);
          liDiv.innerHTML = "<a href='#' onclick=\"location.href=" +
            "'http://translate.google.com/translate?langpair=" +
            from_lang + "&" + to_lang + "&hl=" + to_lang +
            "&ie=UTF-8&oe=UTF-8&u='" +
            " + encodeURIComponent(location.href)\">" +
            "<img border=0 src='" + images + flag + ".png' /> " + name + "</a>";
        }
        var getme = "<a href='http://drnicwilliams.com/2006/08/30/foreign-tourists-to-your-websites-part-2/'>How to translate my site?</a>";
        var getme_li = document.createElement("li");
        getme_li.innerHTML = getme;
        ulDiv.appendChild(getme_li);
      </script>

[1] Americans mightn't know that when foreigners visitor your country, we are presented with paperwork to fillout that refers to us as Aliens. Perhaps your government never watches its own Hollywood movies, but this isn't the best phrase to use, I think. Not very welcoming.

Yehuda Katz starts a blog

Yehuda is the creator of autoDB – the wonderful admin console for Rails – and Visual jQuery – a dazzling set of documentation for the jQuery javascript library. I think many Prototype/Scriptaculous/Rails users would like to see their documentation be as attractive and complete as the Visual jQuery docco. (Which is generated from the jQuery libraries and marked up via XLS translation).

Fortunately, he’s started a blog.

We’ve had lots of discussions together about many topics over recent times, and anyone who places me at the top of their blogroll, must be a good bloke. :)

[ANN] Spy on the Japanese Rubists

Their Ruby code is surrounded by a shrouded of Japanese symbols. You know there is gold in there, but its left to the reader to interpret the purpose of the article. Happy Japanese man? Cranky Japanese man?

The creator of Ruby is Japanese, the Rubist magazine is in Japanese, and a great many users of Ruby are Japanese, yet I can’t understand a word they are saying. That’s not their fault. It’s my French teacher’s fault.

Wonder no longer. Thanks to Google Translate’s Japanese to English translation and the Bookmarklet feature of Firefox (and other browsers?)

Drag this Bookmarklet into your links toolbar, and start spying on the Japanese.

Bookmarklet: Spy on Japanese

Want to spy on the Germans? Drag it again, and change the embedded url. Look for the langpair=ja&en and change ja to de. (Cheat: Spy on Germans)

Want to encourage our Japanese friends to spy on you? Perhaps add links on your pages for instant translations from English to Japanese (change ja -> en, and en -> ja), and change the hl=en to hl=ja.

<a href="#" onclick="location.href='http://translate.google.com/translate?langpair=en&ja&hl=ja&ie=UTF-8&oe=UTF-8&u=' + encodeURIComponent(location.href)">Translate into Japanese</a>

Test this here: