Hacking Django and GlotPress Together

First there’s the question of why you’d want to do this. Glotpress is but one of several open-source web-based translation managers. It’s built on PHP and mySQL. Transifex and Pootle are more robust and built on Django. Nevertheless, I chose Glotpress because of its small codebase and light resource usage (helps me save $$$ on Webfaction). There’s also the dead simple interface. And hey, it’s used by WordPress and Gravatar.

If that makes any sense, know that Glotpress is intended to integrate with an existing user registration mechanism (it doesn’t come with it’s own). Glotpress uses Backpress and can integrate with WordPress auth through a config setting, but that’s of little use to a Django app. In my case, authentication is handled by Django (with registration by django-registration) and Glotpress just piggybacks off the Django session. You can see this in action at Opencooks.com. If you’re interested in using Glotpress with your Django app, here’s one way to go about it.

Continue reading

Multilingual Sorting in Django with ICU and PyICU

Presenting a dropdown country list in multiple languages on a registration or profile form is perhaps one of the more common, initial challenges when internationalizing in Django. The aim is to present the countries dropdown not only translated, but sorted in some natural language order.

This requires unicode collation support that Python does not have built in. For very large datasets that are expected to grow even larger, database collation will likely scale better. Postgres supports per-column collation as well as a collate clause starting from version 9.1 (however, Django ORM doesn’t seem to have support for this so raw queries may be needed). But for small fixed-sized datasets, like a country list, application-side sorting is acceptable. This works especially well if you are using a country app (like django-countries) that stores the countries in code as a list of tuples, which makes it easy to manipulate. For in-python sorting we turn to the ICU project, an internationalization library available in C++ and Java, and PyICU, the Python wrapper for ICU.

Continue reading

Setting up and Securing Apache Solr on Webfaction

A guide to setting up Solr with jetty on Webfaction’s doesn’t appear to exist yet on the internets, so I’m giving it a go. Keep in mind Solr is rather memory hungry so you may want to look to alternatives before proceeding.

I’m using django with the django-haystack app to tap into Solr, so there may be references to specific frameworks or modules. 

Continue reading