[ZPT] CVS: Zope/lib/python/Products/PageTemplates/tests - testHTMLTests.py:1.14.4.3

Florent Guillaume fg@nuxeo.com
Sun, 15 Sep 2002 20:44:01 -0400


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

Modified Files:
      Tag: Zope-2_6-i18n-branch
	testHTMLTests.py 
Log Message:
Added a hookable global translation service to PageTemplates, with tests.

A third-party product wishing to add a translation service simply has to
do:
    from Products.PageTemplates.GlobalTranslationService import \
         setGlobalTranslationService
    setGlobalTranslationService(mytranslationservice)
A translation service only needs one method, whose signature is:
    def translate(self, domain, msgid, mapping=None,
                  context=None, target_language=None)
It must return a translated string based on msgid and the domain, and
optionally the other arguments. The translated string can be Unicode.


=== Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py 1.14.4.2 => 1.14.4.3 ===
--- Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py:1.14.4.2	Sun Sep 15 20:00:46 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testHTMLTests.py	Sun Sep 15 20:43:30 2002
@@ -15,6 +15,8 @@
 
 from Products.PageTemplates.tests import util
 from Products.PageTemplates.PageTemplate import PageTemplate
+from Products.PageTemplates.GlobalTranslationService import \
+     setGlobalTranslationService
 from AccessControl import SecurityManager
 from AccessControl.SecurityManagement import noSecurityManager
 
@@ -25,6 +27,10 @@
 class Folder(util.Base):
     pass
 
+class TestTranslationService:
+    def translate(self, domain, msgid, *args, **kw):
+        return "[%s](%s)" % (domain, msgid)
+
 
 class UnitTestSecurityPolicy:
     """
@@ -135,6 +141,14 @@
 
     def checkUnicodeInserts(self):
         self.assert_expected_unicode(self.folder.t, 'CheckUnicodeInserts.html')
+
+    def checkI18nTranslate(self):
+        self.assert_expected(self.folder.t, 'CheckI18nTranslate.html')
+
+    def checkI18nTranslateHooked(self):
+        old_ts = setGlobalTranslationService(TestTranslationService())
+        self.assert_expected(self.folder.t, 'CheckI18nTranslateHooked.html')
+        setGlobalTranslationService(old_ts)
 
 def test_suite():
     return unittest.makeSuite(HTMLTests, 'check')