Trees | Index | Help |
|
---|
Package zope :: Package configuration :: Module fields :: Class 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 Text | |
| |
Inherited from MinMaxLen | |
| |
Inherited from Field | |
| |
| |
| |
| |
| |
| |
| |
| |
Inherited from Element | |
Returns the documentation for the object. | |
Returns the name of the object. | |
Returns the value associated with 'tag'. | |
Returns a list of all tags. | |
Returns the value associated with 'tag'. | |
Associates 'value' with 'key'. | |
Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__repr__() <==> repr(x) | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) |
Class Variable Summary | |
---|---|
Implements |
__implemented__ = <implementedBy zope.configuration.fiel...
|
ClassProvides |
__provides__ = <zope.interface.declarations.ClassProvide...
|
dict |
_MessageID__factories = {}
|
Inherited from MinMaxLen | |
ClassProvides |
__providedBy__ = <zope.interface.declarations.ClassProvi...
|
FieldProperty |
max_length = <zope.schema.fieldproperty.FieldProperty ob...
|
FieldProperty |
min_length = <zope.schema.fieldproperty.FieldProperty ob...
|
Inherited from Field | |
object |
_Field__missing_value_marker = <object object at 0xb7e6e...
|
NoneType |
_type = None |
NoneType |
context = None |
ValidatedProperty |
default = <zope.schema._bootstrapfields.ValidatedPropert...
|
FieldProperty |
description = <zope.schema.fieldproperty.FieldProperty o...
|
NoneType |
missing_value = None |
int |
order = 285 |
FieldProperty |
readonly = <zope.schema.fieldproperty.FieldProperty obje...
|
FieldProperty |
required = <zope.schema.fieldproperty.FieldProperty obje...
|
FieldProperty |
title = <zope.schema.fieldproperty.FieldProperty object ...
|
Inherited from Attribute | |
NoneType |
interface = None |
Class Variable Details |
---|
__implemented__
|
__provides__
|
_MessageID__factories
|
Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Fri Jun 24 12:01:19 2005 | http://epydoc.sf.net |