diff --git a/product/ERP5Type/patches/Localizer.py b/product/ERP5Type/patches/Localizer.py index 63c00303af6d914c6e41a3038e05f7f95dc9a2b6..c0fb08c41f5b9d355e7f39ad59c51c58c0534ada 100755 --- a/product/ERP5Type/patches/Localizer.py +++ b/product/ERP5Type/patches/Localizer.py @@ -12,21 +12,19 @@ # ############################################################################## -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 ERP5Form. +# file in patches directory. try: from string import Template except ImportError: from Products.ERP5Type.patches.string import Template - +from Products.CMFCore.utils import getToolByName +from Products.Localizer.MessageCatalog import _marker class LocalizerTranslationService: def translate( self, domain, msgid - , mapping=None, context=None, target_language=None, default=None + , mapping=None, context=None, target_language=None, default=_marker , *args, **kw): """ This translate() method use Localizer and support catalog aliases. @@ -36,22 +34,16 @@ class LocalizerTranslationService: message_catalog_aliases = { "ui" : "erp5_ui" , "content": "erp5_content" } - + # Get Localizer - localizer = getToolByName(context, 'Localizer') + localizer = getToolByName(self, 'Localizer') # Get the Localizer catalog id - catalog_id = None - if domain in message_catalog_aliases.keys(): - catalog_id = message_catalog_aliases[domain] - else: - catalog_id = domain + catalog_id = message_catalog_aliases.get(domain, domain) if catalog_id not in localizer.objectIds(): # No catalog found: return the untranslated string return msgid + catalog_obj = localizer[catalog_id] - # Adapt Translation Service default value to the Localizer one - if default == None: - default = msgid # Call the Message Catalog gettext method translated_str = catalog_obj.gettext( message = msgid , lang = target_language @@ -62,11 +54,10 @@ class LocalizerTranslationService: return translated_str - # Use the patched translate() method -from Products.PageTemplates import GlobalTranslationService +from Products.Localizer import GlobalTranslationService, Localizer -def setGlobalTranslationService(service): - GlobalTranslationService.translationService = LocalizerTranslationService() +GlobalTranslationService.translate = LocalizerTranslationService.translate +Localizer.Localizer.translate = LocalizerTranslationService.translate +Localizer.Localizer.tranlate__roles__ = None # public -GlobalTranslationService.setGlobalTranslationService = setGlobalTranslationService