Tuesday, February 2, 2010

Automating translation template generation and check-ins for Launchpad

I previously wrote about how excited I was for the automated translation import and export features of Launchpad. Launchpad will automatically notice when you commit a translation template and import it, making it available for translation online. Generous translators will then contribute translations, and Launchpad will commit them back to your project.

Okay, so this is pretty good! However for this process to work well, the translation template needs to be generated manually by a developer whenever there are changes to strings. Otherwise, translators are working on potentially outdated strings; some are perhaps not in the application anymore, and there are likely some strings which aren't in the template yet.

After forgetting to generate and commit my template until shortly before a release more than once (and thus having poor translation coverage on newly added strings), I decided to automate this part of the process as well. All it took was a relatively small script to generate the template, and then if there were any changes, commit and push to the branch configured for automatic import in Launchpad. The following script does just that, by searching for any files using gettext calls starting with _(" or _(', and passing them to xgettext.

set -e
ack-grep "_\([\"\']" -l | xargs xgettext --output=wxbanker/po/wxbanker.pot
ACTUALCHANGES="`bzr diff | grep \"^[\-\+]msg\" | wc -l`"
if [[ "$ACTUALCHANGES" != "0" ]]; then
bzr ci -m "automated generation of translation template"
bzr push :parent

Note that if you aren't using Python, you may need to tweak the regular expression supplied to ack-grep. Once the template is generated, the diff is piped through grep to grab any changes to actual messages and make sure there was at least one. Otherwise there would always be changes due to the timestamp in the template, causing useless commits.

I then threw this script into a Hudson job, the Continuous Integration server I use for wxBanker. I configured this particular job to run nightly, pulling down the latest bzr branch beforehand, and emailing me on any failures.

It seems to be working quite well and ensures translators are always translating the latest strings and leaves nothing for me to forget, smoothing out the release process.

If this sounds interesting to you but you're not familiar with Launchpad as a translation system, check out http://blog.launchpad.net/general/trying-out-launchpad-translations and feel free to ask any questions here. If you do have experience with translations, how do you handle generating translation templates and then integrating the translations?

No comments: