[Zope3-checkins] SVN: Zope3/trunk/src/zope/tal/ Teach tal about the
new i18nmessageid.Message class.
Gary Poster
gary at zope.com
Fri Apr 15 12:20:02 EDT 2005
Log message for revision 30007:
Teach tal about the new i18nmessageid.Message class.
Changed:
U Zope3/trunk/src/zope/tal/dummyengine.py
U Zope3/trunk/src/zope/tal/talinterpreter.py
U Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py
-=-
Modified: Zope3/trunk/src/zope/tal/dummyengine.py
===================================================================
--- Zope3/trunk/src/zope/tal/dummyengine.py 2005-04-15 16:19:09 UTC (rev 30006)
+++ Zope3/trunk/src/zope/tal/dummyengine.py 2005-04-15 16:20:02 UTC (rev 30007)
@@ -21,7 +21,7 @@
from zope.tal.taldefs import NAME_RE, TALExpressionError, ErrorInfo
from zope.tal.interfaces import ITALExpressionCompiler, ITALExpressionEngine
from zope.i18n.interfaces import ITranslationDomain
-from zope.i18nmessageid import MessageID
+from zope.i18nmessageid import MessageID, Message
Default = object()
@@ -137,7 +137,7 @@
def evaluateText(self, expr):
text = self.evaluate(expr)
- if isinstance(text, (str, unicode, MessageID)):
+ if isinstance(text, (str, unicode, MessageID, Message)):
return text
if text is not None and text is not Default:
text = str(text)
@@ -280,10 +280,12 @@
# by calling that method.
# MessageID attributes override arguments
- if isinstance(msgid, MessageID):
+ if isinstance(msgid, (MessageID, Message)):
domain = msgid.domain
mapping = msgid.mapping
default = msgid.default
+ if default is None: # Message doesn't substitute itself for
+ default = msgid # missing default
# simulate an unknown msgid by returning None
if msgid == "don't translate me":
Modified: Zope3/trunk/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/talinterpreter.py 2005-04-15 16:19:09 UTC (rev 30006)
+++ Zope3/trunk/src/zope/tal/talinterpreter.py 2005-04-15 16:20:02 UTC (rev 30007)
@@ -21,7 +21,7 @@
# Do not use cStringIO here! It's not unicode aware. :(
from StringIO import StringIO
-from zope.i18nmessageid import MessageID
+from zope.i18nmessageid import MessageID, Message
from zope.tal.taldefs import quote, TAL_VERSION, METALError
from zope.tal.taldefs import isCurrentVersion
from zope.tal.taldefs import getProgramVersion, getProgramMode
@@ -579,7 +579,7 @@
if text is self.Default:
self.interpret(stuff[1])
return
- if isinstance(text, MessageID):
+ if isinstance(text, (MessageID, Message)):
# Translate this now.
text = self.engine.translate(text)
# '&' must be done first!
@@ -618,7 +618,7 @@
value = self.engine.evaluate(expression)
# evaluate() does not do any I18n, so we do it here.
- if isinstance(value, MessageID):
+ if isinstance(value, (MessageID, Message)):
# Translate this now.
value = self.engine.translate(value)
Modified: Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py 2005-04-15 16:19:09 UTC (rev 30006)
+++ Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py 2005-04-15 16:20:02 UTC (rev 30007)
@@ -27,7 +27,7 @@
from zope.tal.talinterpreter import TALInterpreter
from zope.tal.dummyengine import DummyEngine, DummyTranslationDomain
from zope.tal.tests import utils
-from zope.i18nmessageid import MessageID
+from zope.i18nmessageid import MessageID, Message
class TestCaseBase(unittest.TestCase):
@@ -145,11 +145,13 @@
self.assertEqual(actual, expected)
-class I18NCornerTestCase(TestCaseBase):
+class I18NCornerTestCaseBase(TestCaseBase):
+ factory = None # set in subclass to Message and MessageID
+
def setUp(self):
self.engine = DummyEngine()
- self.engine.setLocal('foo', MessageID('FoOvAlUe', 'default'))
+ self.engine.setLocal('foo', self.factory('FoOvAlUe', 'default'))
self.engine.setLocal('bar', 'BaRvAlUe')
def _check(self, program, expected):
@@ -295,7 +297,12 @@
"Foo <span tal:replace='bar' i18n:name='bar' /></div>")
self._check(program, u"<div>FOO \u00C0</div>\n")
+class I18NCornerTestCaseMessageID(I18NCornerTestCaseBase):
+ factory = MessageID
+class I18NCornerTestCaseMessage(I18NCornerTestCaseBase):
+ factory = Message
+
class ScriptTestCase(TestCaseBase):
def setUp(self):
@@ -515,7 +522,8 @@
suite.addTest(unittest.makeSuite(MacroExtendTestCase))
suite.addTest(unittest.makeSuite(OutputPresentationTestCase))
suite.addTest(unittest.makeSuite(ScriptTestCase))
- suite.addTest(unittest.makeSuite(I18NCornerTestCase))
+ suite.addTest(unittest.makeSuite(I18NCornerTestCaseMessageID))
+ suite.addTest(unittest.makeSuite(I18NCornerTestCaseMessage))
suite.addTest(unittest.makeSuite(TestSourceAnnotations))
# TODO: Deactivated test, since we have not found a solution for this and
More information about the Zope3-Checkins
mailing list