International Python

François Pinard pinard at iro.umontreal.ca
Thu Jan 13 15:05:46 EST 2000


Hi, people.

Things are improving in the area of Python internationalisation! :-) After
having made PO mode able to mark strings for translation in a collection
of Python sources, I finally got `xpot' to extract those strings into a
neater POT file.  I'm grateful to Barry Warsaw for his `pygettext' tool,
which has been useful to cross-check the results of 'xpot' and debug it.

`xpot' uses the same principles that guided PO mode scanning for Python.
Adjacent strings (those only separated by whitespace or comments)
are correctly concatenated at extraction time.  Strings are considered
translatable if they are used within _(STRING) or gettext(STRING) constructs,
other keywords may be added, of course.  Also, to palliate the lack of a
pre-processor, strings which translation should be delayed may be marked
as translatable by using one of ''"text", ''r"text", ""'text' or ""r'text'.
I might address ''"""text""" and ""'''text''' as well if deemed useful.

One option to `xpot' allows for automatic extraction of all doc strings,
which never need explicit marking for this reason.  I think I got it right:
doc strings should be correctly found even after very complex initialisation
of keyword parameters.  I do not expect this to be common use, but this
might be useful in highly interactive programs giving access to Python
internal code, a bit like Emacs already does for its own LISP.

`xpot' is also able to extract translatable strings from Emacs LISP files,
as well as from other pre-existing PO files.  To find out the language,
it looks for hints in file name, in `#!PATH/env PROGRAM', `#!PATH/PROGRAM',
`-*-mode:MODE-*-' or `-*-MODE-*-' in the first two lines.  I did not recheck
Emacs LISP or PO recently, but found out on the whole Emacs, that `xpot'
fails on raw-Mule files.  My plan is to complete `xpot' so it can also handle
C/C++ (`xgettext' makes this one less urgent), and later `awk', Perl and
`bash', or in fact, anything that could help internationalisation! :-)

`xpot' is itself written in C, Flex and Bison, and I would expect it to be
rather fast even for big projects.  I intend to put out an alpha version
for pretest, probably soon, and then tell you where to find it.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list