International Python

François Pinard pinard at iro.umontreal.ca
Sat Jan 15 20:15:08 EST 2000


[My notes tell me I replied to Martin only, while my intent was to include
 python-list as well.  Sorry if I'm mistaken and this happens to be a
 duplicate.]

Martin von Loewis <loewis at informatik.hu-berlin.de> écrit:

> Are there plans to have the interpreter put the translations into the
> __doc__ strings?  If so, how would that work?

None that I know.  So far that I see, the main (other) difficulty would
be to statically attach a textual domain to the doc string.

If you have a complex Python package made up of components, or sub-packages,
each using a different textual domain, (this is where we all go), it may
be hopeless to try dynamically switch the "default" translation domain.
I would have a suggestion, however.  `_' could be bound, near the very
beginning of each module, by something resembling:

        _ = intl.translator(DOMAIN)

with DOMAIN being component-specific string, that is, always the same for
all modules which are part of a sub-package.  This, in turn, would check
if a Translator object for DOMAIN already exists (just looking it up in a
dictionary).  If not, a new such object would be created.  self.domain would
be bound to DOMAIN, and the `translator' function from that object would
be returned by `intl.translator'.  The Translator.translator function would
be nothing else than a call to `dcgettext' with domain set to self.domain.

Then, to print any string from a given MODULE from outside, including its
doc string, would could merely and safely use MODULE._(MODULE.STRING).

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






More information about the Python-list mailing list