Implement a getGlobalTranslationService replacement for Zope 2.12, but use the...

Implement a getGlobalTranslationService replacement for Zope 2.12, but use the one Zope 2.8 if available (approved by jm).

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30015 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a24deeca
...@@ -30,20 +30,56 @@ from Products.ERP5Type.Globals import InitializeClass, Persistent ...@@ -30,20 +30,56 @@ from Products.ERP5Type.Globals import InitializeClass, Persistent
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
try: try:
from Products.PageTemplates.GlobalTranslationService import getGlobalTranslationService from Products.PageTemplates.GlobalTranslationService import getGlobalTranslationService
# on Zope 2.8
except ImportError: except ImportError:
import zLOG, sys # on Zope 2.12
zLOG.LOG('Products.ERP5Type.Messages', import zLOG, sys
zLOG.ERROR, zLOG.LOG('Products.ERP5Type.Messages',
'Products.PageTemplates.GlobalTranslationService has been removed. ' zLOG.ERROR,
'Translation services for Message will be disabled', 'Products.PageTemplates.GlobalTranslationService has been removed. '
error=sys.exc_info()) 'Using alternative implementation',)
def getGlobalTranslationService(): import zope.i18n
zLOG.LOG('Products.ERP5Type.Messages', from zope.i18n.interfaces import ITranslationDomain
zLOG.WARNING, from Acquisition import aq_get
'not returning a translation service!')
return None class GlobalTranslationService(object):
""" GlobalTranslationService replacement """
# inspired by the old Localizer GlobalTranslationService
def getTranslateMethod(self, context, domain):
"""Returns either the translate() method of an appropriate Localizer
MessageCatalog or zope.i18n.translate
"""
if context is None:
return zope.i18n.translate
# Try to get a catalog from a Localizer Object using acquisition
# FIXME: This should be fixed to use queryUtility instead, but only
# after ERP5Site starts implementing ISite so that MessageCatalogs can
# registerm themselves as local utilities.
# translation_domain = zope.component.getUtility(ITranslationDomain,
# domain,
# context=context)
translation_domain = context.unrestrictedTraverse(("Localizer", domain),
None)
# FIXME: Remove this check once we're using getUtility
if ITranslationDomain.providedBy(translation_domain):
return translation_domain.translate
return zope.i18n.translate
def translate(self, domain, msgid, context=None, **kw):
translate = self.getTranslateMethod(context, domain)
# For zope.i18n, the 'context' of a translation request is actually the
# an IBrowserRequest, for languate negotiation (see, for instance,
# Products.CMFPlone.TranslationServiceTool). The new localizer
# MessageCatalog abides by the zope.i18n.interface definitions.
# (Actually, it ignores the context).
request = aq_get(context, 'REQUEST', None)
return translate(msgid=msgid, domain=domain, context=request, **kw)
getGlobalTranslationService = GlobalTranslationService
from Products.ERP5Type.Globals import get_request from Products.ERP5Type.Globals import get_request
from cPickle import dumps, loads from cPickle import dumps, loads
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment