Python And Internationalization maybe a pre-pep?
Martin v. Löwis
martin at v.loewis.de
Sun Jan 11 22:18:51 CET 2004
Brian Kelley <bkelley at wi.mit.edu> writes:
> def foo(...):
> return i"Message"
> You wouldn't have to execute foo directly for the parse tree to notice
> that i"Message" was a string that is supposed to be
> internationalized. This process gets this string placed in the
> internationalization table which I would then use various tools to
> modify and translate.
But this is the technology today! The xgettext utility (either
GNU xgettext, or xgettext.py) extracts internationalized strings
from Python code into "internationalization tables". These tables
are called "PO files". They get translated, then converted into
an efficient internal representation, called "mo files".
I'm uncertain how this relates to the internationalization tables
you are proposing, but please recognize that a single application
may have *multiple* such tables, called "textual domains". To
find a translation, you not only need the message id, but you
also need the textual domain.
> This should tranparent to Gui Widgets and the like so you can place
> i"Message" in a list box, it will automatically get internationalized
> but when you get the result of the user selected, it still can be used
> to dictionary look ups exactly the same as the original i"Message".
Using what textual domain?
> My current thinking is as follows, I could get most of this effect by
> not having a new string type (i"") and just making an
> internationalization string type. Then I would just use code analyzer
> tools to generate the translation tables as Serge suggested, heck,
> they could even use the parse module if I was so inclined.
xgettext.py already performs very simple parsing of source files,
to extract messages. Why reinvent the wheel?
> In either case, I far prefer using internation("This is good") over
> the _("This is good") function call.
So do call it internation(), or internationalization() or something
else. It is just a function:
return gettext.dgettext("some domain", msg)
More information about the Python-list