[Zope3-dev] SimpleTerm from MessageID

Dmitry Vasiliev lists at hlabs.spb.ru
Fri Mar 18 03:46:26 EST 2005


Gary Poster wrote:

 > On Mar 17, 2005, at 9:59 AM, Dmitry Vasiliev wrote:
 >
 >> Hello all!
 >>
 >> I want to make registration status widget fully translatable.
 >> Although InactiveStatus and ActiveStatus is both MesssageID instances,
 >> translation is not performed, since the term.title value always equal
 >> None. So I want to make special case for SimpleTerm values:
 >>
 >> if title is None and isinstance(value, MessageID):
 >>     title = value
 >>
 >> Is this reasonable change? If so then I check it in with tests.
 >
> It would be better if the term was instantiated with a title set.  Is 
> that easy to do instead?  I don't know what "ActiveStatus" is, in context.

Active(Inactive)Status defined like this:

     InactiveStatus = _('Inactive')
     ActiveStatus = _('Active')

and then later Choice field created like this:

     status = Choice(
         title=_("Registration status"),
         values=(InactiveStatus, ActiveStatus),
         default=ActiveStatus
         )

so SimpleVocabulary created:

     if values is not None:
         self.vocabulary = SimpleVocabulary.fromValues(values)

The fromValues() classmethod simply calls SimpleTerm(value) for all values.


I think it would be even better if title, if not defined, will be set 
automatically from MessageID value when SimpleTerm will be created. It will be 
more generic approach and when you will create vocabularies like above, term 
title will be set automatically.

-- 
Dmitry Vasiliev (dima at hlabs.spb.ru)
     http://hlabs.spb.ru


More information about the Zope3-dev mailing list