Proposed PEP for a Conditional Expression

Christian Tanzer tanzer at swing.co.at
Wed Sep 12 08:52:25 CEST 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote:

> "Christian Tanzer" <tanzer at swing.co.at> writes:
>     ...
> """
> > print "%(plur_verb number 'Found') %(plur_noun number 'error')s" % neater
> > 
> > with the parser in __getitem__ looking for spaces and using
> > them, if found, to recognize formatting keywords such as
> > 'plur_verb' -- makes for easier parsing AND for vastly easier
> > i18n of messages (neater itself would of course use gettext
> > as needed on the meaning-carrying words such as 'error' or
> > 'Found':-).
> 
> Well, I'd use the contents of the interpolated string as key to get 
> the translation (via gettext or otherwise). After all, different
> languages might have totally different rules how to adapt a sentence
> to the context supplied by `neater`.
> """
> In my experience that doesn't work well when the messages
> include numbers that can vary all over the place, like,
> here, the number of errors -- the i18n db gets overwhelmed
> by almost-identical messages.  Yes, working by fragments
> isn't quite as satisfactory -- here, I'm forcing the
> verb to come before the direct object, for example, and
> that might not be ideal for some languages -- that would
> need some extra tricks.

Sorry for my unclear wording.

I wanted to say I would use something like (with `_` a suitable function
returning the translated text):

  _("string to be interpolated containing conditional code") % context

i.e., use the template (before interpolation) -- takes just one key per
sentence and still allows all the variation necessary to support the
wide variety of grammars out there (and I know that there are more
variations than I know about <wink>). If one used such an
architecture, the conditional operators inside the templates must be
understood by the translators. So it better were readable and robust. 

I cannot imagine how your proposal using `plur_noun` &c. functions
could really be made to fly -- word order varies wildly between
languages. [Disclaimer: I'm not a linguist and the only languages I
know in any detail are German and English. Besides, I don't have any
practical experience with I18N yet.]

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list