[Erp5-report] r11785 - /erp5/trunk/products/ERP5Type/patches/Localizer.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Dec 22 18:03:17 CET 2006


Author: jerome
Date: Fri Dec 22 18:03:14 2006
New Revision: 11785

URL: http://svn.erp5.org?rev=11785&view=rev
Log:
don't be too silent when we cannot acquire a Localizer object for translate


Modified:
    erp5/trunk/products/ERP5Type/patches/Localizer.py

Modified: erp5/trunk/products/ERP5Type/patches/Localizer.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/Localizer.py?rev=11785&r1=11784&r2=11785&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/Localizer.py (original)
+++ erp5/trunk/products/ERP5Type/patches/Localizer.py Fri Dec 22 18:03:14 2006
@@ -12,8 +12,6 @@
 #
 ##############################################################################
 
-from Products.CMFCore.utils import getToolByName
-
 # Template() is a new method of python 2.4, that's why we have the string.py
 #   file in patches directory.
 try:
@@ -22,7 +20,7 @@
   from Products.ERP5Type.patches.string import Template
 
 from Products.ERP5Type.Message import Message
-from zLOG import LOG
+from zLOG import LOG, ERROR
 
 class LocalizerPatchError(Exception):
   """Error wen trying to use or apply the Localizer patch"""
@@ -30,7 +28,9 @@
 # This patch will not work if Translation Service Zope product exist on the system
 try:
   from Products import TranslationService
-  LOG("LocalizerPatchError", 100,"Translation Service Zope Product (%s) and Translation Service tools must be deleted to let Localizer Patch work." % (repr(TranslationService)))
+  LOG("ERP5Type.patches.Localizer", ERROR, "Translation Service Zope Product"
+      " (%s) and Translation Service tools must be deleted to let Localizer "
+      "Patch work." % (repr(TranslationService)))
 except ImportError:
   pass
 
@@ -83,12 +83,13 @@
   if context is None:
     # Placeless!
     return msgid
-  # XXX patch -because if context is ZMailIn, it is at the site root
-  # and does not find Localizer by acquisition
-  try:
-    return context.Localizer.translate(domain, msgid, *args, **kw)
-  except AttributeError:
+
+  localizer = getattr(context, 'Localizer', None)
+  if localizer is None:
+    LOG('ERP5Type.patches.Localizer', ERROR, 'could not find a Localizer '
+         'object in acquisition context, message will not be translated')
     return msgid
+  return localizer.translate(domain, msgid, *args, **kw)
 
 # Apply the monkey patch.
 from Products.Localizer.Localizer import Localizer




More information about the Erp5-report mailing list