Package zope :: Package configuration :: Module fields :: Class MessageID
[show private | hide private]
[frames | no frames]

Type MessageID

object --+                
         |                
   Element --+            
             |            
     Attribute --+        
                 |        
             Field --+    
                     |    
        object --+   |    
                 |   |    
         MinMaxLen --+    
                     |    
                  Text --+
                         |
                        MessageID


Text string that should be translated.

When a string is converted to a message ID, it is also recorded in the context.

>>> class Info(object):
...     file = 'file location'
...     line = 8
>>> class FauxContext(object):
...     i18n_strings = {}
...     info = Info()
>>> context = FauxContext()
>>> field = MessageID().bind(context)

There is a fallback domain when no domain has been specified.

Exchange the warn function so we can make test whether the warning has been issued

>>> warned = None
>>> def fakewarn(*args, **kw):
...     global warned
...     warned = args
>>> import warnings
>>> realwarn = warnings.warn
>>> warnings.warn = fakewarn
>>> i = field.fromUnicode(u"Hello world!")
>>> i
u'Hello world!'
>>> i.domain
'untranslated'
>>> warned
("You did not specify an i18n translation domain for the '' field in file location",)
>>> warnings.warn = realwarn

With the domain specified:

>>> context.i18n_strings = {}
>>> context.i18n_domain = 'testing'

We can get a message id:

>>> i = field.fromUnicode(u"Hello world!")
>>> i
u'Hello world!'
>>> i.domain
'testing'

In addition, the string has been registered with the context:

>>> context.i18n_strings
{'testing': {u'Hello world!': [('file location', 8)]}}
>>> i = field.fromUnicode(u"Foo Bar")
>>> i = field.fromUnicode(u"Hello world!")
>>> from pprint import PrettyPrinter
>>> pprint=PrettyPrinter(width=70).pprint
>>> pprint(context.i18n_strings)
{'testing': {u'Foo Bar': [('file location', 8)],
             u'Hello world!': [('file location', 8),
                               ('file location', 8)]}}
>>> from zope.i18n.messageid import MessageID
>>> isinstance(context.i18n_strings['testing'].keys()[0], MessageID)
1

Explicit Message IDs

>>> i = field.fromUnicode(u'[View-Permission] View')
>>> i
u'View-Permission'
>>> i.default
u'View'
>>> i = field.fromUnicode(u'[] [Some] text')
>>> i
u'[Some] text'
>>> i.default
u'[Some] text'

Method Summary
  fromUnicode(self, u)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
Implements __implemented__ = <implementedBy zope.configuration.fiel...
ClassProvides __provides__ = <zope.interface.declarations.ClassProvide...

Class Variable Details

__implemented__

Type:
Implements
Value:
<implementedBy zope.configuration.fields.MessageID>                    

__provides__

Type:
ClassProvides
Value:
<zope.interface.declarations.ClassProvides object at 0xb64a828c>       

Generated by Epydoc 2.1 on Fri Jun 24 12:01:19 2005 http://epydoc.sf.net