[Zope3-checkins] SVN: Zope3/trunk/src/zope/i18n/t Added logic to
ignore message domains for fallback domains.
Jim Fulton
jim at zope.com
Tue Nov 8 17:57:46 EST 2005
Log message for revision 39991:
Added logic to ignore message domains for fallback domains.
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 2005-11-08 22:57:44 UTC (rev 39990)
+++ Zope3/trunk/src/zope/i18n/tests/test_translationdomain.py 2005-11-08 22:57:45 UTC (rev 39991)
@@ -16,6 +16,7 @@
$Id$
"""
import unittest, os
+from zope.testing import doctest
from zope.i18n.translationdomain import TranslationDomain
from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
from zope.i18n.tests.test_itranslationdomain import \
@@ -126,11 +127,43 @@
"this THAT the other")
+def test_message_domain_ignored_by_fallback_domain():
+ """\
+
+Normally, a translation domain will try to lookup an alternative
+translation domain if a message's domain is different than it's own:
+
+ >>> domain = TranslationDomain('mydomain')
+ >>> msgid = MessageIDFactory('huh')(u'short_greeting', 'default')
+ >>> domain.translate(msgid, target_language='en')
+ ... # doctest: +NORMALIZE_WHITESPACE
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError:
+ (<InterfaceClass zope.i18n.interfaces.ITranslationDomain>, 'huh')
+
+
+However, fallback domains, which have an empty domain name, ignore
+message domains:
+
+ >>> domain = TranslationDomain('')
+ >>> path = testdir()
+ >>> en_catalog = GettextMessageCatalog('en', 'other',
+ ... os.path.join(path, 'en-default.mo'))
+ >>> domain.addCatalog(en_catalog)
+ >>> domain.translate(msgid, target_language='en')
+ u'Hello!'
+
+Fallback domains are used mainly for testing.
+
+"""
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestGlobalTranslationDomain))
+ suite.addTest(doctest.DocTestSuite())
return suite
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
-if __name__ == '__main__':
- unittest.TextTestRunner().run(test_suite())
Modified: Zope3/trunk/src/zope/i18n/translationdomain.py
===================================================================
--- Zope3/trunk/src/zope/i18n/translationdomain.py 2005-11-08 22:57:44 UTC (rev 39990)
+++ Zope3/trunk/src/zope/i18n/translationdomain.py 2005-11-08 22:57:45 UTC (rev 39991)
@@ -85,10 +85,8 @@
# MessageID attributes override arguments
if isinstance(msgid, (Message, MessageID)):
- if msgid.domain != self.domain:
+ if (msgid.domain != self.domain) and self.domain:
util = getUtility(ITranslationDomain, msgid.domain)
- return util.translate(msgid, mapping, context,
- target_language, default)
mapping = msgid.mapping
default = msgid.default
More information about the Zope3-Checkins
mailing list