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
...@@ -31,18 +31,54 @@ from AccessControl import ClassSecurityInfo ...@@ -31,18 +31,54 @@ 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:
# on Zope 2.12
import zLOG, sys import zLOG, sys
zLOG.LOG('Products.ERP5Type.Messages', zLOG.LOG('Products.ERP5Type.Messages',
zLOG.ERROR, zLOG.ERROR,
'Products.PageTemplates.GlobalTranslationService has been removed. ' 'Products.PageTemplates.GlobalTranslationService has been removed. '
'Translation services for Message will be disabled', 'Using alternative implementation',)
error=sys.exc_info()) import zope.i18n
def getGlobalTranslationService(): from zope.i18n.interfaces import ITranslationDomain
zLOG.LOG('Products.ERP5Type.Messages', from Acquisition import aq_get
zLOG.WARNING,
'not returning a translation service!') class GlobalTranslationService(object):
return None """ 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