[Zope-Checkins] CVS: Zope/lib/python/Products/PageTemplates - GlobalTranslationService.py:1.4 TALES.py:1.37
Fred L. Drake, Jr.
fred@zope.com
Mon, 7 Apr 2003 13:38:57 -0400
Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv18558/Products/PageTemplates
Modified Files:
GlobalTranslationService.py TALES.py
Log Message:
Back-port two features from the Zope 3 version of Page Templates:
- avoid normalizing whitespace when using the default text when there is not
a matching translation
- added support for explicit msgids in the i18n:attributes syntax
=== Zope/lib/python/Products/PageTemplates/GlobalTranslationService.py 1.3 => 1.4 ===
--- Zope/lib/python/Products/PageTemplates/GlobalTranslationService.py:1.3 Sun Oct 6 13:21:07 2002
+++ Zope/lib/python/Products/PageTemplates/GlobalTranslationService.py Mon Apr 7 13:38:27 2003
@@ -16,11 +16,19 @@
$Id$
"""
+import re
+
+from DocumentTemplate.DT_Util import ustr
+from TAL.TALDefs import NAME_RE
+
class DummyTranslationService:
"""Translation service that doesn't know anything about translation."""
def translate(self, domain, msgid, mapping=None,
- context=None, target_language=None):
- return None
+ context=None, target_language=None, default=None):
+ def repl(m, mapping=mapping):
+ return ustr(mapping[m.group(m.lastindex)])
+ cre = re.compile(r'\$(?:(%s)|\{(%s)\})' % (NAME_RE, NAME_RE))
+ return cre.sub(repl, default or msgid)
# XXX Not all of Zope.I18n.ITranslationService is implemented.
translationService = DummyTranslationService()
=== Zope/lib/python/Products/PageTemplates/TALES.py 1.36 => 1.37 ===
--- Zope/lib/python/Products/PageTemplates/TALES.py:1.36 Wed Oct 9 10:40:33 2002
+++ Zope/lib/python/Products/PageTemplates/TALES.py Mon Apr 7 13:38:27 2003
@@ -247,12 +247,14 @@
self.position = position
def translate(self, domain, msgid, mapping=None,
- context=None, target_language=None):
+ context=None, target_language=None, default=None):
if context is None:
context = self.contexts.get('here')
return getGlobalTranslationService().translate(
domain, msgid, mapping=mapping,
- context=context, target_language=target_language)
+ context=context,
+ default=default,
+ target_language=target_language)
class TALESTracebackSupplement:
"""Implementation of ITracebackSupplement"""