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 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...
|
Class Variable Details |
---|
__implemented__
|
__provides__
|
Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Fri Jun 24 12:01:19 2005 | http://epydoc.sf.net |