Check out the new USENIX Web site. next up previous
Next: Future and Related Work Up: GNU Mailman, Internationalized Previous: Other Issues

Examples

Here is some sample Python code (reformatted for this paper) taken from Mailman 2.1 which shows marked messages:

label = _(categories[category])
realname = mlist.real_name
doc.SetTitle(
    _('%(realname)s Administration '
      '(%(label)s)'))
doc.AddItem(Center(Header(2, _(
    '%(realname)s mailing list '
    'administration<br>%(label)s '
    'Section'))))

Notice first that the local variables ``label'' and ``realname'' are referenced in the default text, and that their values come from the magic interpolation described above. In a translated message the order of the substitutions may change, so this ensures that the substitutions will occur in the grammatically correct location in the translated message. Also notice that there are actually three uses of the underscore function. In the second and third, the only function arguments are strings (in Python, adjacent strings are concatenated by the lexer). The pygettext rule for message extraction is a single string inside the underscore function, so both these texts will be extracted into the message catalog.

The first use of the underscore function is interesting in that it is getting a value out of a dictionary lookup. This is an example of a deferred translation, where the underscore function is only used for its run-time behavior. The text returned by the dictionary lookup is translated in a normal fashion, but the program source code categories[category] isn't extracted into the catalog because it isn't a string.

At the place where the categories dictionary is defined, the strings are also wrapped in an underscore function for pygettext extraction, but they aren't translated at that place in the program. We do this in a number of situations, such as when dictionaries are defined in module global scope. In that case, you would see something like:

def _(s): return s

categories = {
    'cat1': _('Privacy'),
    'cat2': _('Autoreplies'),
    'cat3': _('Topics'),
    }

_ = i18n._

Here, we're marking three strings for extraction, but we aren't translating them at the point of definition, because the target locale isn't known at this time.

Due to space limitations, sample web pages can't be included, however a public internationalized list can be viewed at https://mail.python.org/mailman/listinfo/playground. You can view this listinfo page in any of the languages supported by Mailman.


next up previous
Next: Future and Related Work Up: GNU Mailman, Internationalized Previous: Other Issues
Barry Warsaw 2003-04-08