[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/locales/ 'tal_strings' being called with 'include_default_domain=True' raised an KeyError because no default catalog existed.

Jodok Batlogg jodok.batlogg at lovelysystems.com
Tue Aug 15 12:44:50 EDT 2006


Log message for revision 69514:
  'tal_strings' being called with 'include_default_domain=True' raised an KeyError because no default catalog existed.
  fixed it and added a test for it.
  

Changed:
  U   Zope3/trunk/src/zope/app/locales/extract.py
  U   Zope3/trunk/src/zope/app/locales/tests.py

-=-
Modified: Zope3/trunk/src/zope/app/locales/extract.py
===================================================================
--- Zope3/trunk/src/zope/app/locales/extract.py	2006-08-15 16:04:37 UTC (rev 69513)
+++ Zope3/trunk/src/zope/app/locales/extract.py	2006-08-15 16:44:49 UTC (rev 69514)
@@ -381,6 +381,31 @@
 
 def tal_strings(dir, domain="zope", include_default_domain=False, exclude=()):
     """Retrieve all TAL messages from `dir` that are in the `domain`.
+    
+      >>> from zope.app.locales import extract
+      >>> import tempfile
+      >>> dir = tempfile.mkdtemp()
+      
+    Let's create a page template in the i18n domain ``test``:
+      >>> testpt = open(os.path.join(dir, 'test.pt'), 'w')
+      >>> testpt.write('<tal:block i18n:domain="test" i18n:translate="">test</tal:block>')
+      >>> testpt.close()
+      
+    And now one in no domain:
+      >>> nopt = open(os.path.join(dir, 'no.pt'), 'w')
+      >>> nopt.write('<tal:block i18n:translate="">no domain</tal:block>')
+      >>> nopt.close()
+      
+    Now let's find the strings for the domain ``test``: 
+      >>> extract.tal_strings(dir, domain='test', include_default_domain=True)
+      {'test': [('...test.pt', 1)], 'no domain': [('...no.pt', 1)]}
+
+
+    Cleanup
+    
+      >>> import shutil
+      >>> shutil.rmtree(dir) 
+
     """
     # We import zope.tal.talgettext here because we can't rely on the
     # right sys path until app_dir has run
@@ -412,6 +437,9 @@
     # When the Domain is 'default', then this means that none was found;
     # Include these strings; yes or no?
     if include_default_domain:
+        defaultCatalog = engine.catalog.get('default')
+        if defaultCatalog == None:
+            engine.catalog['default'] = {}
         catalog.update(engine.catalog['default'])
     for msgid, locations in catalog.items():
         catalog[msgid] = map(lambda l: (l[0], l[1][0]), locations)

Modified: Zope3/trunk/src/zope/app/locales/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/locales/tests.py	2006-08-15 16:04:37 UTC (rev 69513)
+++ Zope3/trunk/src/zope/app/locales/tests.py	2006-08-15 16:44:49 UTC (rev 69514)
@@ -15,12 +15,14 @@
 
 $Id$
 """
+import doctest
 import unittest
 from zope.testing.doctestunit import DocTestSuite
 
 def test_suite():
     return unittest.TestSuite((
-        DocTestSuite('zope.app.locales.extract'),
+        DocTestSuite('zope.app.locales.extract',
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,),
         ))
 
 if __name__ == '__main__':



More information about the Zope3-Checkins mailing list