gittip/www.gittip.com — pull request #2599 by oakes (2014-07-27 01:29:19+00:00)
Title: Internationalize user interface messages

This branch will fix #957 by providing internationalization support to Gittip. There is plenty more to do, but I want to get feedback on the approach before I spend too much time on it.

To try it out, you'll need to install Babel with pip and then change your browser's language settings to make Esperanto the primary language. In Chrome's settings, there is a "Language and input settings" button that allows you to set it as the first language.

The translations are stored as `po` files in the `i18n` directory, which are all read into a dictionary in `gittip/utils/__init__.py`. That file also has a few functions that can be used everywhere a string needs to be localized:

* `parse_locale(request)` takes a Request object and returns a locale code, such as "en-US", based on whatever the user's browser sent in the `Accept-Language` header. If there is no translation for any language in the header, it defaults to English.
* `_(s, loc)` takes a string and locale code, and returns either the translated string if available, or the string itself otherwise.
* `to_localized_age(dt, loc)`, which takes a DateTime object and locale code, and returns a string similar to what `to_age` provides except it is localized by Babel.

In simplates, we can then replace hard-coded English strings with something like this: `{{ _("Edit", loc) }}`. In cases where a string needs to contain dynamic content, we can use `format` like this: `{{ _("{0} joined recently", loc).format(participant.username) }}`. Any feedback on this would be great.