[Zope-Checkins] SVN: Products.Five/trunk/ merged r71088 from 1.5
branch:
Yvo Schubbe
y.2006_ at wcm-solutions.de
Mon Nov 6 09:55:05 EST 2006
Log message for revision 71089:
merged r71088 from 1.5 branch:
- backported changes from Zope 3.3's zope.i18n
Changed:
U Products.Five/trunk/CHANGES.txt
U Products.Five/trunk/i18n.py
U Products.Five/trunk/tests/test_i18n.py
-=-
Modified: Products.Five/trunk/CHANGES.txt
===================================================================
--- Products.Five/trunk/CHANGES.txt 2006-11-06 14:46:59 UTC (rev 71088)
+++ Products.Five/trunk/CHANGES.txt 2006-11-06 14:55:04 UTC (rev 71089)
@@ -11,6 +11,12 @@
* Port code from Zope 3 making resource directories recursive.
Thanks to Richard Waid.
+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/trunk/i18n.py
===================================================================
--- Products.Five/trunk/i18n.py 2006-11-06 14:46:59 UTC (rev 71088)
+++ Products.Five/trunk/i18n.py 2006-11-06 14:55:04 UTC (rev 71089)
@@ -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/trunk/tests/test_i18n.py
===================================================================
--- Products.Five/trunk/tests/test_i18n.py 2006-11-06 14:46:59 UTC (rev 71088)
+++ Products.Five/trunk/tests/test_i18n.py 2006-11-06 14:55:04 UTC (rev 71089)
@@ -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)
More information about the Zope-Checkins
mailing list