Archive for September, 2011

Speed Scrabble Notifier for Firefox

Wednesday, September 28th, 2011

If you’re a Speed Scrabble player and running Firefox, then you might be interested in trying the new Speed Scrabble Extension.

The add-on helps you keep track of who is currently online so you can easily drop in for a game. Try it out!.

Speed Scrabble is a fast, fun and free online multiplayer word game. If you’ve not played it before then check it out!

If you aren’t a Firefoxer, there are similar extensions for Safari and Chrome.

If you’re a software developer interested in seeing how the extension works, the source code is freely available and can be used for any purpose.

If you have any thoughts on the new extension, feel free to get in touch!

Book Review – Supercharged JavaScript Graphics by Raffaele Cecco (O’Reilly Media)

Sunday, September 18th, 2011

Supercharged JavaScript Graphics provides an introduction to a number of modern and practical JavaScript topics.

This book is well-written and easy to read, with relevant, practical examples. It covers a wide range of topics, centred around dynamic graphics and game development, including:

  • Profiling and optimization
  • DHTML Sprites
  • The Canvas element
  • Vector graphics
  • Visualizations with the Google Charts API
  • Mobile app development with JavaScript

Each topic is covered in enough detail to get you started, without getting particularly involved in too many specifics. Presumably if any topic piques your interest you can investigate further.

I found this book to be an easy read and a good introduction to a number of interesting JavaScript topics. The book is particularly relevant for game development with an excellent example of how to develop a complete game with JavaScript and jQuery.

The examples in this book are excellent – well written, well explained, and typically complete and usable. It’s obvious that Raffaele knows his craft.

The book also provides an excellent overview of the current state of JavaScript and gives you a good idea of what can currently be accomplished with a pure HTML/CSS/JavaScript solution.

The only addition I would like to see is a section with recommendations for more in-depth information. Overall though this is a good practical introduction to JavaScript graphics.

Note: This book was provided by O’Reilly Media as part of their blogger review program.

I review for the O'Reilly Blogger Review Program

Python localization made easy

Friday, September 16th, 2011

Here’s a set of simple steps to localize a Python application for different translations. This tutorial provides a clear set of steps with sample code.

Step 1: Initialize your application

Here is the code to initialize your application with localization enabled:

If you can’t see the source code try here.

This snippet looks for a resource file based on the users locale. For instance, “res/” for English. If it fails to open the appropriate translation file, it falls back to NullTranslations, which simply performs no translation.

Step 2: Prepare your application for translation

trans.install() generates a global function available to all modules in your application: _().

Find all the strings in your application that you wish to translate, and wrap them with the _() function.

i.e. “Hello” becomes _(“Hello”).

This applies to parameterized strings as well. e.g. “Hello %s” % name becomes _(“Hello %s”) % name.

Step 3: Generate the pot

That’s messages.pot.

Run the command xgettext *.py or pygettext *.py. Under Windows, you might have to look for this tool. Under the Python installation directory, try Tools/i18n.

This command looks for all strings inside the _() function, and generates the file messages.pot.

Step 4: Translate

Send your generated pot file to your translator. They will replace the empty strings with the appropriate translations and return the file to you.

Step 5: Generate the mo

Save the returned file to reflect the new language that your application has been translated to. e.g. messages_De.po

Run the command msgfmt -o res/ messages_De.po to generate the required .mo file.

As with pygettext, if your system doesn’t find this command, look in Tools/i18n under the Python installation directory.

After running this command, the translation file required by the application will be in the res directory. When you’re distributing the application, make sure the res directory goes too.

Step 6: Test

On Windows XP, you can change your locale with the following steps:

  • Start->Control Panel->Regional and Language Options;
  • Under “Regional Options”, choose the locale for the translation file you have created and click “Apply”;
  • Start the Python application;
  • (Hopefully) enjoy your translated application!

In summary…

It’s straightforward to setup localization with Python once you know how.