[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/ No longer rely on the PageTemplates.GlobalTranslationService but use zope.i18n.translate directly.
Hanno Schlichting
plone at hannosch.info
Sat Feb 21 11:19:18 EST 2009
Log message for revision 96961:
No longer rely on the PageTemplates.GlobalTranslationService but use zope.i18n.translate directly.
Changed:
U Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt
U Products.CMFDefault/trunk/Products/CMFDefault/utils.py
-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt 2009-02-21 16:13:08 UTC (rev 96960)
+++ Products.CMFDefault/trunk/Products/CMFDefault/CHANGES.txt 2009-02-21 16:19:18 UTC (rev 96961)
@@ -4,6 +4,9 @@
2.2.0 (unreleased)
------------------
+- No longer rely on the PageTemplates.GlobalTranslationService but use
+ zope.i18n.translate directly.
+
- Cleaned up / normalized imports:
o Don't import from Globals; instead, use real locations.
Modified: Products.CMFDefault/trunk/Products/CMFDefault/utils.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/utils.py 2009-02-21 16:13:08 UTC (rev 96960)
+++ Products.CMFDefault/trunk/Products/CMFDefault/utils.py 2009-02-21 16:19:18 UTC (rev 96961)
@@ -24,9 +24,8 @@
import StringIO
from AccessControl.SecurityInfo import ModuleSecurityInfo
+from Acquisition import aq_get
from App.Common import package_home
-from Products.PageTemplates.GlobalTranslationService \
- import getGlobalTranslationService
from ZTUtils.Zope import complex_marshal
from zope.component import getUtility
@@ -34,6 +33,7 @@
from zope import i18n # disambiguation
from zope.i18n.interfaces import IUserPreferredCharsets
from zope.i18nmessageid import MessageFactory
+from zope.publisher.interfaces.browser import IBrowserRequest
from Products.CMFCore.interfaces import IPropertiesTool
@@ -467,14 +467,21 @@
def translate(message, context):
""" Translate i18n message.
"""
- GTS = getGlobalTranslationService()
if isinstance(message, Exception):
try:
message = message[0]
except (TypeError, IndexError):
pass
- return GTS.translate('cmf_default', message, context=context)
+ # in Zope3, context is adapted to IUserPreferredLanguages,
+ # which means context should be the request in this case.
+ # Do not attempt to acquire REQUEST from the context, when we already
+ # got a request as the context
+ if context is not None:
+ if not IBrowserRequest.providedBy(context):
+ context = aq_get(context, 'REQUEST', None)
+ return i18n.translate(message, domain='cmf_default', context=context)
+
security.declarePublic('getBrowserCharset')
def getBrowserCharset(request):
""" Get charset preferred by the browser.
More information about the Checkins
mailing list