[Checkins] SVN: z3c.pt/trunk/src/z3c/pt/ Renable tests in i18n. Add some for i18n:name.

Sylvain Viollon sylvain at infrae.com
Thu Oct 30 11:29:43 EDT 2008


Log message for revision 92705:
  Renable tests in i18n. Add some for i18n:name.
  
  

Changed:
  U   z3c.pt/trunk/src/z3c/pt/README.txt
  U   z3c.pt/trunk/src/z3c/pt/i18n.txt
  U   z3c.pt/trunk/src/z3c/pt/tests/test_doctests.py

-=-
Modified: z3c.pt/trunk/src/z3c/pt/README.txt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/README.txt	2008-10-30 15:26:49 UTC (rev 92704)
+++ z3c.pt/trunk/src/z3c/pt/README.txt	2008-10-30 15:29:43 UTC (rev 92705)
@@ -8,10 +8,10 @@
 --------------
 
   >>> from z3c.pt.pagetemplate import ZopePageTemplate
-  >>> from z3c.pt.pagetemplate import ZopePageTemplateFile  
+  >>> from z3c.pt.pagetemplate import ZopePageTemplateFile
 
 The ``ZopePageTemplate`` class is initialized with a string.
-  
+
   >>> print ZopePageTemplate("""\
   ... <div xmlns="http://www.w3.org/1999/xhtml">
   ...   Hello World!
@@ -22,7 +22,7 @@
 
 The ``ZopePageTemplateFile`` class is initialized with an absolute
 path to a template file on disk.
-  
+
   >>> from z3c.pt import tests
   >>> path = tests.__path__[0]
   >>> t = ZopePageTemplateFile(path+'/helloworld.pt')
@@ -40,19 +40,19 @@
 
   >>> from z3c.pt.pagetemplate import ViewPageTemplate
   >>> from z3c.pt.pagetemplate import ViewPageTemplateFile
-  
+
   >>> class View(object):
   ...     request = u'request'
   ...     context = u'context'
   ...
   ...     def __repr__(self):
   ...         return 'view'
-  
+
   >>> view = View()
 
 As before, we can initialize view page templates with a string (here
 incidentally loaded from disk).
-  
+
   >>> template = ViewPageTemplate(
   ...     open(path+'/view.pt').read())
 
@@ -68,9 +68,9 @@
     <span>request</span>
     <span>test</span>
   </div>
-  
+
 The exercise is similar for the file-based variant.
-  
+
   >>> template = ViewPageTemplateFile(path+'/view.pt')
   >>> print template.bind(view)(test=u'test')
   <div>
@@ -85,7 +85,7 @@
 
   >>> from z3c.pt.texttemplate import ViewTextTemplate
   >>> from z3c.pt.texttemplate import ViewTextTemplateFile
-  
+
   >>> template = ViewTextTemplate(open(path+'/view.css').read())
   >>> print template.bind(view)(color=u'#ccc')
   #region {

Modified: z3c.pt/trunk/src/z3c/pt/i18n.txt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/i18n.txt	2008-10-30 15:26:49 UTC (rev 92704)
+++ z3c.pt/trunk/src/z3c/pt/i18n.txt	2008-10-30 15:29:43 UTC (rev 92705)
@@ -23,7 +23,10 @@
   ...         if target_language != 'de':
   ...             return default
   ...
-  ...         return "Mock translation of '%s'." % msgid
+  ...         mock ="Mock translation of '%s'" % msgid
+  ...         if mapping:
+  ...             mock += ' mapping=%s' % mapping
+  ...         return mock + '.'
 
   >>> td = MockTranslationDomain()
   >>> component.provideUtility(td, ITranslationDomain, name="test")
@@ -47,7 +50,7 @@
   >>> template = PageTemplate(body)
 
 Let's try rendering this template without passing a target language.
-    
+
   >>> print template.render()
   <div>
     <span>
@@ -63,7 +66,7 @@
   </div>
 
 Let's try infering the translation message id from the tag body.
-  
+
   >>> body = """\
   ... <div xmlns="http://www.w3.org/1999/xhtml"
   ...      xmlns:i18n="http://xml.zope.org/namespaces/i18n">
@@ -83,7 +86,7 @@
   </div>
 
 Passing German:
-  
+
   >>> print template.render(target_language='de')
   <div>
     <span>Mock translation of 'Default'.</span>
@@ -106,17 +109,52 @@
       <span>18</span> bananas.
     </p>
   </div>
-    
+
   >>> print template.render(target_language='de')
   <div>
-    <p>Mock translation of '${count} bananas.'.</p>
+    <p>Mock translation of '${count} bananas.'
+       mapping={'count': '<span>18</span>'}
+    </p>
   </div>
 
+Or two:
+
+  >>> body = """\
+  ... <div xmlns="http://www.w3.org/1999/xhtml"
+  ...      xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+  ...   <span i18n:domain="test" i18n:translate="">
+  ...     I want <span i18n:name="bananas">12</span> bananas and
+  ...     <span i18n:name="apples">8</span> apples.
+  ...   </span>
+  ... </div>"""
+
+Without a language this gives:
+
+  >>> template = PageTemplate(body)
+  >>> print template.render()
+  <div>
+    <span>
+       I want <span>12</span> bananas and
+       <span>8</span> apples.
+    </span>
+  </div>
+
+In German:
+
+  >>> print template.render(target_language='de')
+  <div>
+    <span>
+      Mock translation of 'I want ${bananas} bananas and  ${apples} apples.'
+      mapping={'bananas': '<span>12</span>', 'apples': '<span>8</span>'}.
+    </span>
+  </div>
+
+
 Translation of tag attributes
 -----------------------------
 
 A simple example to start with.
-  
+
   >>> body = """\
   ... <div xmlns="http://www.w3.org/1999/xhtml"
   ...      xmlns:i18n="http://xml.zope.org/namespaces/i18n">
@@ -240,7 +278,7 @@
 ---------------------------------------------
 
 A simple example to start with.
-  
+
   >>> body = """\
   ... <div xmlns="http://www.w3.org/1999/xhtml"
   ...      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
@@ -273,3 +311,4 @@
     <span title="Mock translation of 'aid'.">Mock translation of 'tid'.</span>
     <span>Mock translation of 'tid'.</span>
   </div>
+

Modified: z3c.pt/trunk/src/z3c/pt/tests/test_doctests.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/test_doctests.py	2008-10-30 15:26:49 UTC (rev 92704)
+++ z3c.pt/trunk/src/z3c/pt/tests/test_doctests.py	2008-10-30 15:29:43 UTC (rev 92705)
@@ -15,22 +15,22 @@
     zope.configuration.xmlconfig.XMLConfig('configure.zcml', z3c.pt)()
 
 def test_suite():
-    filesuites = 'README.txt',
+    filesuites = 'README.txt', 'i18n.txt',
     testsuites = 'z3c.pt.expressions',
-    
+
     config.DISK_CACHE = False
-    
+
     return unittest.TestSuite(
         [zope.testing.doctest.DocFileSuite(
         doctest, optionflags=OPTIONFLAGS,
         setUp=setUp, tearDown=zope.component.testing.tearDown,
         package="z3c.pt") for doctest in filesuites] + \
-        
+
         [zope.testing.doctest.DocTestSuite(
         doctest, optionflags=OPTIONFLAGS,
         setUp=setUp, tearDown=zope.component.testing.tearDown) \
          for doctest in testsuites]
-        
+
         )
 
 if __name__ == '__main__':



More information about the Checkins mailing list