[Zope3-checkins] CVS: Zope3/src/zope/configuration - fields.py:1.13
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Aug 18 16:20:52 EDT 2003
Update of /cvs-repository/Zope3/src/zope/configuration
In directory cvs.zope.org:/tmp/cvs-serv30443/configuration
Modified Files:
fields.py
Log Message:
Implemented new syntax for assigning "explicit" Message IDs in ZCML.
The Syntax:
<.... attr="[MessageID] Default Text" />
<... attr="[] [Escaped] Default Text" />
While other solutions were proposed, this one was the only one that would
not require a total rethinking/rewrite of the ZCML internals (and we just
has a ZCMLgeddon, so I think it will not happen soon again. ;-)
=== Zope3/src/zope/configuration/fields.py 1.12 => 1.13 ===
--- Zope3/src/zope/configuration/fields.py:1.12 Tue Aug 5 10:56:05 2003
+++ Zope3/src/zope/configuration/fields.py Mon Aug 18 15:20:18 2003
@@ -347,6 +347,20 @@
{'testing': {u'Foo Bar': [('file location', 8)],
u'Hello world!': [('file location', 8),
('file location', 8)]}}
+
+ 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'
"""
implements(IFromUnicode)
@@ -364,6 +378,15 @@
)
v = super(MessageID, self).fromUnicode(u)
+ # Check whether there is an explicit message is specified
+ default = None
+ if v.startswith('[]'):
+ v = v[3:]
+ elif v.startswith('['):
+ end = v.find(']')
+ default = v[end+2:]
+ v = v[1:end]
+
# Record the string we got for the domain
i18n_strings = context.i18n_strings
strings = i18n_strings.get(domain)
@@ -379,4 +402,4 @@
factory = zope.i18n.messageid.MessageIDFactory(domain)
self.__factories[domain] = factory
- return factory(v)
+ return factory(v, default)
More information about the Zope3-Checkins
mailing list