[Zope3-checkins] CVS: Zope3/src/zope/configuration - fields.py:1.9
Philipp von Weitershausen
philikon at philikon.de
Mon Aug 4 13:57:44 EDT 2003
Update of /cvs-repository/Zope3/src/zope/configuration
In directory cvs.zope.org:/tmp/cvs-serv6611
Modified Files:
fields.py
Log Message:
Accept MessageID fields without an i18n domain (the fallback will be
'untranslated'). Issue a warning, though.
=== Zope3/src/zope/configuration/fields.py 1.8 => 1.9 ===
--- Zope3/src/zope/configuration/fields.py:1.8 Mon Aug 4 07:12:06 2003
+++ Zope3/src/zope/configuration/fields.py Mon Aug 4 12:57:39 2003
@@ -15,7 +15,7 @@
$Id$
"""
-import os, re
+import os, re, warnings
from zope import schema
from zope.schema.interfaces import IFromUnicode
from zope.configuration.exceptions import ConfigurationError
@@ -293,15 +293,21 @@
>>> context = FauxContext()
>>> field = MessageID().bind(context)
- We can't do anything if we don't have a domain:
+ There is a fallback domain when no domain has been specified.
+ Suppress warnings so they won't show up when running unit tests.
- >>> i = field.fromUnicode("Hello world!")
- Traceback (most recent call last):
- ...
- ConfigurationError: You must specify a an i18n translation domain
+ >>> import warnings
+ >>> warnings.filterwarnings('ignore')
+
+ >>> i = field.fromUnicode(u"Hello world!")
+ >>> i
+ u'Hello world!'
+ >>> i.domain
+ 'untranslated'
With the domain specified:
+ >>> context.i18n_strings = {}
>>> context.i18n_domain = 'testing'
We can get a message id:
@@ -335,8 +341,10 @@
context = self.context
domain = getattr(context, 'i18n_domain', '')
if not domain:
- raise ConfigurationError(
- "You must specify a an i18n translation domain")
+ domain = 'untranslated'
+ warnings.warn(
+ "You did not specify an i18n translation domain for the "\
+ "'%s' field in %s" % (self.getName(), context.info ))
v = super(MessageID, self).fromUnicode(u)
# Record the string we got for the domain
More information about the Zope3-Checkins
mailing list