Discussion:
[Erp5-dev] a patch for Localizer patch
Bartłomiej Górny
2006-12-21 15:39:52 UTC
Permalink
Hello

There is sometimes a problem with GlobalTranslationService - in
ERP5Type/patches/Localizer.py it relies on acquisition to find the Localizer
object. But if we are processing an email received by zope, we are in context
of ZMailIn instance, and Localizer can't be found.

So we should either do the simplest thing possible - return untranslated
message:

Index: ERP5Type/patches/Localizer.py
===================================================================
--- ERP5Type/patches/Localizer.py (r??vision 11733)
+++ ERP5Type/patches/Localizer.py (copie de travail)
@@ -83,9 +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:
+ return msgid

- return context.Localizer.translate(domain, msgid, *args, **kw)
-
# Apply the monkey patch.
from Products.Localizer.Localizer import Localizer
Localizer.translate = Localizer_translate

or assume the site is under /erp5, or use some other way of finding ERP5Site
and get Localizer from there.

Bartek
Yoshinori Okuji
2006-12-21 15:58:36 UTC
Permalink
Post by Bartłomiej Górny
There is sometimes a problem with GlobalTranslationService - in
ERP5Type/patches/Localizer.py it relies on acquisition to find the
Localizer object. But if we are processing an email received by zope, we
are in context of ZMailIn instance, and Localizer can't be found.
I don't object to your patch, but how do you pass email to Zope? What I did in
the past was like this:

address: "|sendEmailToZope http://localhost:8080/erp5/scriptToDealWithEmail"

YO
--
Yoshinori Okuji, Nexedi CTO
Nexedi: Consulting and Development of Free / Open Source Software
http://www.nexedi.com
ERP5: Full Featured High End Open Source ERP
http://www.erp5.com
ERP5 Wiki: Developer Zone for ERP5 Community
http://www.erp5.org
Bartłomiej Górny
2006-12-22 11:42:55 UTC
Permalink
Post by Yoshinori Okuji
Post by Bartłomiej Górny
There is sometimes a problem with GlobalTranslationService - in
ERP5Type/patches/Localizer.py it relies on acquisition to find the
Localizer object. But if we are processing an email received by zope, we
are in context of ZMailIn instance, and Localizer can't be found.
I don't object to your patch, but how do you pass email to Zope? What I did
address: "|sendEmailToZope
http://localhost:8080/erp5/scriptToDealWithEmail"
Ah, so you don't have the problem because you skip ZMailIn and call the script
directly. My "sendEmailToZope" script finds a ZMailIn object on the target
host, and the script is configured in ZMailIn. So the context is different.

Bartek
Post by Yoshinori Okuji
YO
Jérôme Perrin
2006-12-22 16:12:32 UTC
Permalink
Post by Bartłomiej Górny
Hello
There is sometimes a problem with GlobalTranslationService - in
ERP5Type/patches/Localizer.py it relies on acquisition to find the
Localizer object. But if we are processing an email received by zope, we
are in context of ZMailIn instance, and Localizer can't be found.
So we should either do the simplest thing possible - return untranslated
Index: ERP5Type/patches/Localizer.py
===================================================================
--- ERP5Type/patches/Localizer.py (r??vision 11733)
+++ ERP5Type/patches/Localizer.py (copie de travail)
@@ -83,9 +83,13 @@
# Placeless!
return msgid
+ # XXX patch -because if context is ZMailIn, it is at the site root
+ # and does not find Localizer by acquisition
+ return context.Localizer.translate(domain, msgid, *args, **kw)
+ return msgid
I'd prefer that we don't hide the exception here.
* this Localizer is registred as GlobalTranslationService for all
i18n:translate in page templates, so if one doesn't have a Localizer object,
it will be a real pain to find out why no translation happen :)
* today, Products.ERP5Type.Message doesn't work in activities with
TimerService, because TimerService's requests
traverse /Control_Panel/timer_service/process_timer, and do not have a
Localizer in REQUEST['PARENTS']

So before we have a clean way to register translation service, I think we
should add a LOG('ERP5Type.patches.Localizer', ERROR, 'Cannot find a
Localizer object in acquisition context, message was not translated')

BTW, I found this in my /etc/postfix/aliases, IIRC I was using CMFMailin, not
ZMailin directly.
mailin: |"erp5mailin:
|"/usr/bin/python /usr/lib/zope/lib/python/Products/CMFMailIn/sendMailToZope.py
http://user:pwd at 127.0.0.1:9080/erp5/portal_mailin"

J?rome

Loading...