[Zope3-checkins] SVN: Zope3/trunk/ Added "test" message catalog for testing i18n. If you specify

Jim Fulton jim at zope.com
Tue Nov 8 15:00:31 EST 2005


Log message for revision 39985:
  Added "test" message catalog for testing i18n.  If you specify
  ++lang++test in a URL, then all translated strings will be
  translated to [[domain][message_id], as in "[[zope][Preview]]".
  Text without the domain marker isn't translated.
  
  Unfortunately, currently you can't tell if it wasn't translated
  because it lacked a message id or if it wasn't translated because there
  was no message catalog.
  
  Yes, this is a new feature, but it's needed to write tests for bug fixes. :P
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/i18n/metaconfigure.py
  U   Zope3/trunk/src/zope/app/i18n/tests/testi18ndirectives.py
  A   Zope3/trunk/src/zope/i18n/testmessagecatalog.py
  A   Zope3/trunk/src/zope/i18n/testmessagecatalog.txt
  A   Zope3/trunk/src/zope/i18n/tests/test_testmessagecatalog.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-11-08 19:53:11 UTC (rev 39984)
+++ Zope3/trunk/doc/CHANGES.txt	2005-11-08 20:00:30 UTC (rev 39985)
@@ -123,6 +123,11 @@
         publishers can be prioritized and publishers can introspect the request
         environment to decide if they can handle a request or not.
 
+      - Added "test" message catalog for testing i18n.  If you specify
+        ++lang++test in a URL, then all translated strings will be
+        translates to [[domain][message_id], as in "[[zope][Preview]]".
+        Text without the domain marker isn't translated.
+
     Restructuring
 
       - Mutable MessageIDs have been deprecated and will be removed in

Modified: Zope3/trunk/src/zope/app/i18n/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/i18n/metaconfigure.py	2005-11-08 19:53:11 UTC (rev 39984)
+++ Zope3/trunk/src/zope/app/i18n/metaconfigure.py	2005-11-08 20:00:30 UTC (rev 39985)
@@ -21,6 +21,7 @@
 
 from zope.app.component.metaconfigure import utility
 from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
+from zope.i18n.testmessagecatalog import TestMessageCatalog
 from zope.i18n.translationdomain import TranslationDomain
 from zope.i18n.interfaces import ITranslationDomain
 
@@ -46,6 +47,11 @@
     # Now create TranslationDomain objects and add them as utilities
     for name, langs in domains.items():
         domain = TranslationDomain(name)
+
         for lang, file in langs.items():
             domain.addCatalog(GettextMessageCatalog(lang, name, file))
+
+        # make sure we have a TEST catalog for each domain:
+        domain.addCatalog(TestMessageCatalog(name))
+
         utility(_context, ITranslationDomain, domain, name=name)

Modified: Zope3/trunk/src/zope/app/i18n/tests/testi18ndirectives.py
===================================================================
--- Zope3/trunk/src/zope/app/i18n/tests/testi18ndirectives.py	2005-11-08 19:53:11 UTC (rev 39984)
+++ Zope3/trunk/src/zope/app/i18n/tests/testi18ndirectives.py	2005-11-08 20:00:30 UTC (rev 39985)
@@ -52,7 +52,7 @@
                             'locale', 'en',
                             'LC_MESSAGES', 'zope-i18n.mo')
         util = zapi.getUtility(ITranslationDomain, 'zope-i18n')
-        eq(util._catalogs, {'en': [unicode(path)]})
+        eq(util._catalogs, {'test': ['test'], 'en': [unicode(path)]})
 
 
 def test_suite():

Added: Zope3/trunk/src/zope/i18n/testmessagecatalog.py
===================================================================
--- Zope3/trunk/src/zope/i18n/testmessagecatalog.py	2005-11-08 19:53:11 UTC (rev 39984)
+++ Zope3/trunk/src/zope/i18n/testmessagecatalog.py	2005-11-08 20:00:30 UTC (rev 39985)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Test message catalog
+
+$Id$
+"""
+
+from zope import interface
+from zope.i18n.interfaces import IGlobalMessageCatalog
+
+class TestMessageCatalog:
+    interface.implements(IGlobalMessageCatalog)
+
+    language = 'test'
+
+    def __init__(self, domain):
+        self.domain = domain
+
+    def queryMessage(self, msgid, default=None):
+        return u'[[%s][%s]]' % (self.domain, msgid)
+
+    getMessage = queryMessage
+
+    def getIdentifier(self):
+        return 'test'
+
+    def reload(self):
+        pass
+
+                     


Property changes on: Zope3/trunk/src/zope/i18n/testmessagecatalog.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/i18n/testmessagecatalog.txt
===================================================================
--- Zope3/trunk/src/zope/i18n/testmessagecatalog.txt	2005-11-08 19:53:11 UTC (rev 39984)
+++ Zope3/trunk/src/zope/i18n/testmessagecatalog.txt	2005-11-08 20:00:30 UTC (rev 39985)
@@ -0,0 +1,22 @@
+Test Message Catalog
+====================
+
+The test message catalog "translates" test by simply outputing the
+domain and message id in square-bracket markers:
+
+    >>> import zope.i18n.testmessagecatalog
+    >>> cat = zope.i18n.testmessagecatalog.TestMessageCatalog('foo.bar')
+
+    >>> cat.language, cat.domain
+    ('test', 'foo.bar')
+
+    >>> cat.queryMessage('eek')
+    u'[[foo.bar][eek]]'
+
+    >>> cat.getMessage('eek')
+    u'[[foo.bar][eek]]'
+
+    >>> cat.getIdentifier()
+    'test'
+
+    >>> cat.reload()


Property changes on: Zope3/trunk/src/zope/i18n/testmessagecatalog.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/trunk/src/zope/i18n/tests/test_testmessagecatalog.py
===================================================================
--- Zope3/trunk/src/zope/i18n/tests/test_testmessagecatalog.py	2005-11-08 19:53:11 UTC (rev 39984)
+++ Zope3/trunk/src/zope/i18n/tests/test_testmessagecatalog.py	2005-11-08 20:00:30 UTC (rev 39985)
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+
+import unittest
+from zope.testing import doctest
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite('../testmessagecatalog.txt'),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+


Property changes on: Zope3/trunk/src/zope/i18n/tests/test_testmessagecatalog.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list