Internationalizing Your WordPress Plugin

We call “internationalization” to the process of setting up software so that it can be used in different languages. In my case I had a plugin with text strings in English and I wanted to add a Portuguese translation. In wp-config.php I set up the WPLANG variable to pt_PT:

define ('WPLANG', 'pt_PT');

I then used poEdit, a localization tool that works with Mac OS X and that can be downloaded from the poEdit download page. In poEdit, from the File menu select ‘New Catalog’. Fill in the information there and in the ‘Paths’ tab put the plugin directory. In the ‘Keywords’ tab add the missing entries so it looks like this:

At this point it should recognize all the text strings in your code and present a screen where you can add the translations. After that be sure to save the file as pluginname-pt_PT.po, preferably in a directory called ‘translations’ or ‘locales’ (but anything will do). After that you’re all set. In your code you should load the translation like this:

load_plugin_textdomain ( 'your-plugin-name' , FALSE , '/your-plugin-name/translations' );

And strings should have the form:

_e('Choose a Category','your-plugin-name');

That’s it. Let me know if you run into troubles :)

Resources & Further Reading for the Geeks:

  • http://codex.wordpress.org/Writing_a_Plugin
  • http://codex.wordpress.org/I18n_for_WordPress_Developers
  • http://urbangiraffe.com/articles/translating-wordpress-themes-and-plugins/
  • http://urbangiraffe.com/articles/localizing-wordpress-themes-and-plugins/

Supond – winner @codebits demo video

@semmais posted a video that shows how it is to interact with “Supond”, our Codebits 2009 project that got elected as the best project. I can’t stop bragging about it :)

Supond is Codebits 2009 Winner!

That’s right, the project me and @semmais did at Codebits 2009 got elected the best among almost 50 other projects.

The Idea – “Apple Time Machine”-like interface to your Lifestream

You’ve probably heard about Apple’s Time Machine, the backup software that lets you navigate back in time and restore files and folders from your hard drive. Well, we thought: “Why not backup your life as well?”. At least your online life. All your tweets, facebook updates, flickr photos, youtube videos, blog posts, etc. What today is called a lifestream. Imagine you can check what happened this same day, one year before. What were you doing? What did you blog about? Any tweets? Maybe you’ve posted photos or videos. That’s what we wanted to do, within a 3D interface inspired by Apple’s Time Machine. Here is a screenshot of how it looked*:

supond

How it Works

We get the lifestream from one of the many aggregators on-line these days. We used the recently launched Sapo’s Pond web service, that aggregates Twitter, Facebook, RSS feeds, Sapo Videos, Sapo Blogs, Sapo Fotos, etc. We get the data via Pond’s API.

The interface was build using Adobe’s Flash and Flex Builder. For the 3D we used the new 3D object manipulation functionality in Flash CS4 and not Papervision3D.

Any service can be easily added as long as there is a RSS feed available. Also it can be used on the web or as a desktop app using Adobe’s Air. Because it is Flash it runs on Windows, Mac and Linux (provided the Flash plugin is installed).

The Prize

1x 13” Apple Macbook Pro notebook, 1x Apple Wireless Keyboard, 1x Apple Magic Mouse, 2x iPod Nano, 1x O’Reilly Book, 3x issues of Make Magazine.

The Story

My project got the first place at Codebits 2009, I was so happy, couldn’t believe it. Especially because of all that happened before, up to that point of our project being announced as the winner. After all I didn’t know the rest of my team until after the programming contest had already started! And they were already doing a project which eventually they put aside to work on “Supond”.

It was the second day of Codebits when the programming contest kicked off and I wasn’t planning on doing any project. I was hanging around with some old friends on the way to some talk when I noticed a couple of guys working with Flex Builder. I had used Flex before so that caught me eye. I approached and started talking about it. They were working on a project already and after a while I commented about an idea I had. Immediately the guys said “hey, that’s a good idea”, and we started prototyping some code. In less than nothing @semmais had some 3D planes lined up for us to use. I started working on the backend to fetch the data via the Pond’s API. @semmais went home at around 20h and I left a bit later, at 22h. We had a nice long night of sleep.

In the next morning we got together again and I had the lifestream data all nicely put in an array for him to populate the interface. He had the nice interface ready to populate and some nice particles in the background with the galaxy picture @jvarandas had done the day before for us. We started integrating. We hacked, hacked, hacked. Integrated support to watch videos and full-sized flickr photos. And we were ready by the time the organization call in the teams for testing the laptops on stage. Great run, great fun. While it was my initial idea I think what worked nicely was that both me, @semmais and @jvarandas fitted nicely as a team and the result came from that. Here’s a photo we took to upload and test the flickr service on Supond:

suponds_team

Thanks

To Paulo Andrade for helping out with the Pond API. It was so good to, when having a problem with the API, just stand up and walk over to the guys that made the thing in the first place.

This year’s competition was largely decided by votes from the audience. We couldn’t have made it if it wasn’t for all the people there that voted on our project. Thanks to all of you.

To Sapo, because I have to, for organizing this cool hacker conference in Portugal.

The Other Projects

Some other teams had really nice projects as well. I particulary liked the “Time-based OTPs” by Paulo Andrade, the  “Simple MBNet” by Pedro Sousa and BlinkBrick, a “lego” like led arduino device by Sergio Veiga. I hope they can finish their projects because they are really cool.

What Now

We are thinking in further developing this idea. If you have suggestions drop us a direct message on Twitter or email. One of the ideas people suggested was to allow saving the data to the hard disk.

* – we’re thinking in posting a live demo for people to play with.

Update: There is now a video demo published.

Advice for Web Entrepreneurs

A collection of items that has been in my inbox for some time:

JavaScript eval() is EVIL

The blogosphere is full of mentions to the worm that is attacking old versions of the Wordpress blog platform and the attack on the popular Scobleizer blog. I was reading about it in the weekend, particularly how the worm works, what it does, how to prevent it and how to recover from it. As Matt Mullenweg, creator of Wordpress, puts it: "This particular worm, like many before it, is clever". One of the things it does is changing the links of the blog to something like this:
/post-title/%&(%7B$%7Beval(base64_decode($_SERVER%5BHTTP_REFERER%5D))%7D%7D|.+)&%/
and this in turn allows evaluated code to be executed. “eval” is evil hum? Although its not something new, still quite cunning. The eval() function evaluates a string and executes it as if it was script code. This means when a user clicks the link on the affected blog, the Javascript arbitrary code will run on the user's browser. Not good. http://wordpress.org/development/2009/09/keep-wordpress-secure/
http://lorelle.wordpress.com/2009/09/04/old-wordpress-versions-under-attack/