Python And Internationalization maybe a pre-pep?
Brian Kelley
bkelley at wi.mit.edu
Fri Jan 9 12:02:36 EST 2004
I have been using gettext and various utilities to provide
internationalization for a wxPython application and have not really been
liking the process. Essentially it uses a macro-style notation to
indicate which strings should be internationalized.
Essentially, everything looks like this
_("STRING")
A good description of this system is located here
http://wiki.wxpython.org/index.cgi/Internationalization
I got to thinking that this is python, I shouldn't have to do this. Why
not have a mechanism to capture this data at compile time?
I made a new python string type and got enough working on the parser to
accept
string = i"whatever"
Which is just a subtype of string. When python parses this it adds it
in an entry in the internationalization table. (essentially a
dictionary) It also addes it as an entry to the standard gettext
mechanism to indicate strings that need to be localized. When the
string is created, if a value exists in the international table for the
given string, the string is converted to the current locale.
The locale is set through the standard locale module. When this
happens, all internationalized strings, when used, are converted to
their international representations (using unicode if necessary)
automagically through the gettext system.
Hopefully I'm not reinventing the wheel but one nice thing about this
system is that after some slight code modifications to the python
sources declaring exception error messages to be international, I now
have a nice dictionary of error messages that need to be localized.
These would be localized in the standard way using gettext tools.
Now, I don't know if this is a good idea or not, and I may be
reinventing some wheels, but it has some appealing characteristics and
ties in with the gettext system really well. Of course, I'm a bit leary
with changing the python parser but I was uncomfortable with the two
step process of writing the code, then passing it through a source
analyzer so that it could be internationalized.
Of course I have some issues, like if you use an international string in
a dictionary and the internal value changes based on the locale bad
things happen. This requires that the locale be set only once at the
beginning of the application otherwise undesirable events occur :)
What I would like is something like
import internationalization
and then at compile time strings like i"whatever" would be analyzed but
would be normal strings without "import internationalization"
So, am I being silly, redundant or just plain different?
Brian
More information about the Python-list
mailing list