Class
zope.configuration.fields.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.i18nmessageid import Message
>>> isinstance(context.i18n_strings['testing'].keys()[0], Message)
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 is None
True

Base classes

Implemented Interfaces

Attributes/Properties

Methods

Known Subclasses

There are no known subclasses.