[Zope3-checkins] SVN: Zope3/trunk/src/zope/i18n/t Added tests for MessageID

Dmitry Vasiliev dima at hlabs.spb.ru
Fri Aug 27 07:40:33 EDT 2004


Log message for revision 27287:
  Added tests for MessageID
  


Changed:
  U   Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py
  U   Zope3/trunk/src/zope/i18n/translationdomain.py


-=-
Modified: Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py
===================================================================
--- Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py	2004-08-27 04:53:17 UTC (rev 27286)
+++ Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py	2004-08-27 11:40:33 UTC (rev 27287)
@@ -21,6 +21,9 @@
 from zope.i18n.tests.test_itranslationdomain import \
      TestITranslationDomain, Environment
 from zope.i18n import MessageIDFactory
+from zope.i18n.interfaces import ITranslationDomain
+from zope.component.servicenames import Utilities
+from zope.component import getGlobalServices
 
 def testdir():
     from zope.i18n import tests
@@ -51,7 +54,6 @@
 
     def testSimpleNoTranslate(self):
         translate = self._domain.translate
-        raises = self.assertRaises
         eq = self.assertEqual
         # Unset fallback translation languages
         self._domain.setLanguageFallbacks([])
@@ -79,19 +81,38 @@
 
     def testStringTranslate(self):
         self.assertEqual(
-            self._domain.translate(u'short_greeting', 'default',
-                                   target_language='en'),
+            self._domain.translate(u'short_greeting', target_language='en'),
             u'Hello!')
 
     def testMessageIDTranslate(self):
+        factory = MessageIDFactory('default')
+        translate = self._domain.translate
+        msgid = factory(u'short_greeting', 'default')
+        self.assertEqual(translate(msgid, target_language='en'), u'Hello!')
+        # MessageID attributes override arguments
+        msgid = factory('43-not-there', 'this ${that} the other')
+        msgid.mapping["that"] = "THAT"
         self.assertEqual(
-            self._domain.translate(u'short_greeting', 'default',
-                                   target_language='en'),
-            u'Hello!')
+            translate(msgid, target_language='en', default="default",
+                         mapping={"that": "that"}), "this THAT the other")
 
+    def testMessageIDTranslateForDifferentDomain(self):
+        domain = TranslationDomain('other')
+        path = testdir()
+        en_catalog = GettextMessageCatalog('en', 'other',
+                                           os.path.join(path, 'en-default.mo'))
+        domain.addCatalog(en_catalog)
+
+        s = getGlobalServices().getService(Utilities)
+        s.provideUtility(ITranslationDomain, domain, 'other')
+
+        factory = MessageIDFactory('other')
+        msgid = factory(u'short_greeting', 'default')
+        self.assertEqual(
+            self._domain.translate(msgid, target_language='en'), u'Hello!')
+
     def testSimpleFallbackTranslation(self):
         translate = self._domain.translate
-        raises = self.assertRaises
         eq = self.assertEqual
         # Test that a translation in an unsupported language returns a
         # translation in the fallback language (by default, English)
@@ -109,8 +130,8 @@
                       default="this ${that} the other",
                       mapping={"that": "THAT"}),
             "this THAT the other")
-        
 
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestGlobalTranslationDomain))

Modified: Zope3/trunk/src/zope/i18n/translationdomain.py
===================================================================
--- Zope3/trunk/src/zope/i18n/translationdomain.py	2004-08-27 04:53:17 UTC (rev 27286)
+++ Zope3/trunk/src/zope/i18n/translationdomain.py	2004-08-27 11:40:33 UTC (rev 27287)
@@ -19,6 +19,8 @@
 from zope.i18n.simpletranslationdomain import SimpleTranslationDomain
 from zope.i18n.messageid import MessageID
 from zope.i18n import interpolate
+from zope.component import getUtility
+from zope.i18n.interfaces import ITranslationDomain
 
 # The configuration should specify a list of fallback languages for the
 # site.  If a particular catalog for a negotiated language is not available,



More information about the Zope3-Checkins mailing list