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
context
(type: NoneType
)
None
default
(type:
ValidatedProperty
)
<zope.schema._bootstrapfields.ValidatedProperty object at 0x40b28f2c>
description
(type:
FieldProperty
)
<zope.schema.fieldproperty.FieldProperty object at 0x40b223ec>
interface
(type: NoneType
)
None
max_length
(type:
FieldProperty
)
<zope.schema.fieldproperty.FieldProperty object at 0x40b22ecc>
min_length
(type:
FieldProperty
)
<zope.schema.fieldproperty.FieldProperty object at 0x40b22e8c>
missing_value
(type: NoneType
)
None
order
(type:
int
)
734
readonly
(type:
FieldProperty
)
<zope.schema.fieldproperty.FieldProperty object at 0x40b2280c>
required
(type:
FieldProperty
)
<zope.schema.fieldproperty.FieldProperty object at 0x40b22d0c>
title
(type:
FieldProperty
)
<zope.schema.fieldproperty.FieldProperty object at 0x40b0208c>
bind(object)
constraint(value)
fromUnicode(u)
get(object)
getDoc()
Returns the documentation for the object.
getName()
Returns the name of the object.
getTaggedValue(tag)
Returns the value associated with tag
.
getTaggedValueTags()
Returns a list of all tags.
query(object, default=None)
queryTaggedValue(tag, default=None)
Returns the value associated with tag
.
set(object, value)
setTaggedValue(tag, value)
Associates value
with key
.
validate(value)
There are no known subclasses.