Log message for revision 71088: - backported changes from Zope 3.3's zope.i18n
Changed: U Products.Five/branches/1.5/CHANGES.txt U Products.Five/branches/1.5/i18n.py U Products.Five/branches/1.5/tests/test_i18n.py -=- Modified: Products.Five/branches/1.5/CHANGES.txt =================================================================== --- Products.Five/branches/1.5/CHANGES.txt 2006-11-06 11:01:25 UTC (rev 71087) +++ Products.Five/branches/1.5/CHANGES.txt 2006-11-06 14:46:59 UTC (rev 71088) @@ -2,6 +2,12 @@ Five Changes ============ +Five 1.5.2 (unreleased) +======================= + +* i18n: Synced FiveTranslationService implementation with Zope 3.3. This makes + sure that the TestMessageFallbackDomain is used if registered. + Five 1.5.1 (2006-11-04) ======================= Modified: Products.Five/branches/1.5/i18n.py =================================================================== --- Products.Five/branches/1.5/i18n.py 2006-11-06 11:01:25 UTC (rev 71087) +++ Products.Five/branches/1.5/i18n.py 2006-11-06 14:46:59 UTC (rev 71088) @@ -17,13 +17,14 @@ """ from Acquisition import aq_acquire from zope.interface import implements -from zope.i18n import interpolate -from zope.i18n.interfaces import ITranslationDomain, IUserPreferredLanguages +from zope.i18n.interfaces import IFallbackTranslationDomainFactory +from zope.i18n.interfaces import ITranslationDomain +from zope.i18n.interfaces import IUserPreferredLanguages from zope.i18n.negotiator import normalize_lang from zope.component import queryUtility -from zope.publisher.browser import BrowserLanguages from zope.i18nmessageid import Message + class FiveTranslationService: """Translation service that delegates to ``zope.i18n`` machinery. """ @@ -36,8 +37,20 @@ default = msgid.default mapping = msgid.mapping - util = queryUtility(ITranslationDomain, domain) + if default is None: + default = unicode(msgid) + if domain: + util = queryUtility(ITranslationDomain, domain) + if util is None: + util = queryUtility(IFallbackTranslationDomainFactory) + if util is not None: + util = util(domain) + else: + util = queryUtility(IFallbackTranslationDomainFactory) + if util is not None: + util = util() + if util is None: # fallback to translation service that was registered, # DummyTranslationService the worst Modified: Products.Five/branches/1.5/tests/test_i18n.py =================================================================== --- Products.Five/branches/1.5/tests/test_i18n.py 2006-11-06 11:01:25 UTC (rev 71087) +++ Products.Five/branches/1.5/tests/test_i18n.py 2006-11-06 14:46:59 UTC (rev 71088) @@ -56,6 +56,38 @@ u'Dies ist eine explizite Nachricht' """ +def test_FiveTranslationService(): + """ + Test FiveTranslationService. First we need the GlobalTranslationService: + + >>> from Products.PageTemplates import GlobalTranslationService + >>> GTS = GlobalTranslationService.getGlobalTranslationService() + + Now, take an arbitrary message id from an arbitrary domain: + + >>> from zope.i18nmessageid import MessageFactory + >>> from zope.i18n import translate + >>> _ = MessageFactory('random') + >>> msg = _(u'explicit-msg', u'This is an explicit message') + + By default, the i18n message is translated by the DummyTranslationService: + + >>> GTS.translate('default', msg, target_language='test') + u'This is an explicit message' + + Now, register the TestMessageFallbackDomain: + + >>> from zope.component import provideUtility + >>> from zope.i18n.testmessagecatalog import TestMessageFallbackDomain + >>> provideUtility(TestMessageFallbackDomain) + + The i18n message is now translated by the TestMessageFallbackDomain: + + >>> GTS.translate('default', msg, target_language='test') + u'[[random][explicit-msg (This is an explicit message)]]' + """ + + def test_suite(): from zope.testing.doctest import DocTestSuite return DocTestSuite(setUp=setUp, tearDown=tearDown) _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins