[Zope-Checkins] CVS: Zope/lib/python/Products/PageTemplates - GlobalTranslationService.py:1.1.4.1 Expressions.py:1.36.6.2 PageTemplate.py:1.25.6.3 PageTemplateFile.py:1.20.2.1 PythonExpr.py:1.8.6.1 TALES.py:1.31.6.1 ZopePageTemplate.py:1.43.2.1

Florent Guillaume fg@nuxeo.com
Wed, 18 Sep 2002 10:54:42 -0400


Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv21162/lib/python/Products/PageTemplates

Modified Files:
      Tag: Zope-2_6-branch
	Expressions.py PageTemplate.py PageTemplateFile.py 
	PythonExpr.py TALES.py ZopePageTemplate.py 
Added Files:
      Tag: Zope-2_6-branch
	GlobalTranslationService.py 
Log Message:
Merge of the Zope-2_6-i18n-branch into Zope-2_6-i18n.

Impacted code:
- TAL: merge of the 2.7 i18n stuff, unicode fixes, tests.
- PageTemplates: addition of a global translation service and of its use
  by the TALES engine, unicode fixes, tests.
- StructuredText: unicode fixes, tests.



=== Added File Zope/lib/python/Products/PageTemplates/GlobalTranslationService.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Global Translation Service for providing I18n to Page Templates.

$Id: GlobalTranslationService.py,v 1.1.4.1 2002/09/18 14:54:11 efge Exp $
"""

class DummyTranslationService:
    """Translation service that does nothing and returns the message id."""
    def translate(self, domain, msgid, mapping=None,
                  context=None, target_language=None):
        return msgid
    # XXX Not all of Zope.I18n.ITranslationService is implemented.

translationService = DummyTranslationService()

def setGlobalTranslationService(service):
    """Sets the global translation service, and returns the previous one."""
    global translationService
    old_service = translationService
    translationService = service
    return old_service

def getGlobalTranslationService():
    """Returns the global translation service."""
    return translationService


=== Zope/lib/python/Products/PageTemplates/Expressions.py 1.36.6.1 => 1.36.6.2 ===
--- Zope/lib/python/Products/PageTemplates/Expressions.py:1.36.6.1	Thu Sep 12 17:56:48 2002
+++ Zope/lib/python/Products/PageTemplates/Expressions.py	Wed Sep 18 10:54:11 2002
@@ -246,7 +246,10 @@
         self._c = compiler.compile(expr)
 
     def __call__(self, econtext):
-        return not econtext.evaluateBoolean(self._c)
+        # We use the (not x) and 1 or 0 formulation to avoid changing
+        # the representation of the result in Python 2.3, where the
+        # result of "not" becomes an instance of bool.
+        return (not econtext.evaluateBoolean(self._c)) and 1 or 0
 
     def __repr__(self):
         return 'not:%s' % `self._s`


=== Zope/lib/python/Products/PageTemplates/PageTemplate.py 1.25.6.2 => 1.25.6.3 ===
--- Zope/lib/python/Products/PageTemplates/PageTemplate.py:1.25.6.2	Sun Sep  8 23:06:51 2002
+++ Zope/lib/python/Products/PageTemplates/PageTemplate.py	Wed Sep 18 10:54:11 2002
@@ -24,7 +24,8 @@
 from TAL.TALGenerator import TALGenerator
 from TAL.TALInterpreter import TALInterpreter
 from Expressions import getEngine
-from cStringIO import StringIO
+# Do not use cStringIO here!  It's not unicode aware. :(
+from StringIO import StringIO
 from ExtensionClass import Base
 from ComputedAttribute import ComputedAttribute
 
@@ -208,3 +209,4 @@
         if e:
             w = list(w) + list(e)
         self.warnings = w
+


=== Zope/lib/python/Products/PageTemplates/PageTemplateFile.py 1.20 => 1.20.2.1 ===
--- Zope/lib/python/Products/PageTemplates/PageTemplateFile.py:1.20	Thu Sep  5 13:55:41 2002
+++ Zope/lib/python/Products/PageTemplates/PageTemplateFile.py	Wed Sep 18 10:54:11 2002
@@ -85,7 +85,8 @@
             response = self.REQUEST.RESPONSE
             if not response.headers.has_key('content-type'):
                 response.setHeader('content-type', self.content_type)
-        except AttributeError: pass
+        except AttributeError:
+            pass
 
         # Execute the template in a new security context.
         security=getSecurityManager()


=== Zope/lib/python/Products/PageTemplates/PythonExpr.py 1.8 => 1.8.6.1 ===
--- Zope/lib/python/Products/PageTemplates/PythonExpr.py:1.8	Wed Aug 14 18:17:24 2002
+++ Zope/lib/python/Products/PageTemplates/PythonExpr.py	Wed Sep 18 10:54:11 2002
@@ -78,3 +78,4 @@
     def __call__(self, text):
         return self._handler(self._name, text,
                              self._econtext._engine)(self._econtext)
+


=== Zope/lib/python/Products/PageTemplates/TALES.py 1.31 => 1.31.6.1 ===
--- Zope/lib/python/Products/PageTemplates/TALES.py:1.31	Wed Aug 14 18:17:24 2002
+++ Zope/lib/python/Products/PageTemplates/TALES.py	Wed Sep 18 10:54:11 2002
@@ -19,6 +19,8 @@
 
 import re, sys, ZTUtils
 from MultiMapping import MultiMapping
+from DocumentTemplate.DT_Util import ustr
+from GlobalTranslationService import getGlobalTranslationService
 
 StringType = type('')
 
@@ -222,11 +224,11 @@
     def evaluateBoolean(self, expr):
         return not not self.evaluate(expr)
 
-    def evaluateText(self, expr, None=None):
+    def evaluateText(self, expr):
         text = self.evaluate(expr)
         if text is Default or text is None:
             return text
-        return str(text)
+        return ustr(text)
 
     def evaluateStructure(self, expr):
         return self.evaluate(expr)
@@ -249,6 +251,11 @@
     def setPosition(self, position):
         self.position = position
 
+    def translate(self, domain, msgid, mapping=None,
+                  context=None, target_language=None):
+        return getGlobalTranslationService().translate(
+            domain, msgid, mapping=mapping,
+            context=context, target_language=target_language)
 
 
 class TALESTracebackSupplement:
@@ -282,3 +289,4 @@
         return self._name, self._expr
     def __repr__(self):
         return '<SimpleExpr %s %s>' % (self._name, `self._expr`)
+


=== Zope/lib/python/Products/PageTemplates/ZopePageTemplate.py 1.43 => 1.43.2.1 ===
--- Zope/lib/python/Products/PageTemplates/ZopePageTemplate.py:1.43	Wed Aug 28 18:18:12 2002
+++ Zope/lib/python/Products/PageTemplates/ZopePageTemplate.py	Wed Sep 18 10:54:11 2002
@@ -369,3 +369,4 @@
         )
     context.registerHelp()
     context.registerHelpTitle('Zope Help')
+