Announcing Babel

20 June 2007

I've just pushed out the first release of a new project that has been in the works for a couple of weeks now: Babel, a Python library for internationalization and localization in Python applications, especially web-based applications.

Babel - Speaking your language

I18n/L10n in Python

I18n aspects of Python web applications have been in a rather sorry state for a long time. Sure, there's good unicode support. And there's the Python locale module that provides access to the POSIX locale database. And there's a gettext module. And some more.

However, there's still a lot of I18n functionality needed by web applications that is not provided by Python, and for which third-party libraries, where available, are not quite appropriate. Web frameworks such as Django, TurboGears, and Pylons have been touting I18n support to different degrees, but the support they provide is very limited, and often doesn't even transcend integration of gettext message catalogs. Try displaying a decimal number in a Django template that uses a comma instead of a period for the decimal point without writing extra code. TurboGears does have some functions for localized number and date formatting, but it, too, is quite limited. There is very little (if any) code shared in this area.

Okay, there is Zope 3, which does have solid I18n support via its zope.i18n package. That package depends on the Zope “kernel” (think interfaces), and I haven't yet found any Python web framework or application outside of the Zope community that uses it. There's also PyICU which the folks at OSAF are using; it is basically a fancy SWIG wrapper around the ICU library. I don't think either of those packages is attractive to the developers of the current generation of Python web frameworks, for a number of reasons I'll avoid getting into here.

What Babel Provides

So here we are: Babel is intended to address these concerns. It bundles a "pre-compiled" version of the Common Locale Data Repository (CLDR), which contains a whole lot of information about many of the worlds different locales. Based on that data, it implements localized date and number formatting (and in a way that doesn't require setting the process-wide locale via the locale module.) It provides data such as the translated names of many of the worlds countries, languages, time-zones, currencies, and more.

That's the part that's comparable to the functionality provided by zope.i18n and PyICU. But there's more. Babel also implements an extensible message catalog extraction system that we think is a better fit for Python applications than good old xgettext. It comes with an extractor for Python source files, but extractors for other source files can be added by third-party packages. The latest release of Genshi, 0.4.2, comes with a Babel plugin that provides simple message extraction from markup and text templates.

Babel does not have any hard dependencies outside of Python itself (there's a dependency on setuptools for the lookup of extractor plugins, but we intend to soften that link in an upcoming release). It's not tied into any particular framework or larger system. It tries to provide functionality in a way that encourages other projects to use it and contribute back, instead of everyone rolling their own limited I18n functionality over and over again.

All that said, this is the first release, and there's still quite a bit of work to do. If you need better internationalization in your Python applications and would like to give Babel a try, or even contribute, we'd be very interested in hearing from you!