Commit 668b1c9c authored by Kevin Deldycke's avatar Kevin Deldycke

Go back to old version of patching method (the one that overide setGlobalTranslationService)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5333 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e6ff1f27
...@@ -22,6 +22,7 @@ except ImportError: ...@@ -22,6 +22,7 @@ except ImportError:
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.Localizer.MessageCatalog import _marker from Products.Localizer.MessageCatalog import _marker
class LocalizerTranslationService: class LocalizerTranslationService:
def translate( self, domain, msgid def translate( self, domain, msgid
, mapping=None, context=None, target_language=None, default=_marker , mapping=None, context=None, target_language=None, default=_marker
...@@ -34,7 +35,6 @@ class LocalizerTranslationService: ...@@ -34,7 +35,6 @@ class LocalizerTranslationService:
message_catalog_aliases = { "ui" : "erp5_ui" message_catalog_aliases = { "ui" : "erp5_ui"
, "content": "erp5_content" , "content": "erp5_content"
} }
# Get Localizer # Get Localizer
localizer = getToolByName(self, 'Localizer') localizer = getToolByName(self, 'Localizer')
# Get the Localizer catalog id # Get the Localizer catalog id
...@@ -42,7 +42,6 @@ class LocalizerTranslationService: ...@@ -42,7 +42,6 @@ class LocalizerTranslationService:
if catalog_id not in localizer.objectIds(): if catalog_id not in localizer.objectIds():
# No catalog found: return the untranslated string # No catalog found: return the untranslated string
return msgid return msgid
catalog_obj = localizer[catalog_id] catalog_obj = localizer[catalog_id]
# Call the Message Catalog gettext method # Call the Message Catalog gettext method
translated_str = catalog_obj.gettext( message = msgid translated_str = catalog_obj.gettext( message = msgid
...@@ -54,15 +53,15 @@ class LocalizerTranslationService: ...@@ -54,15 +53,15 @@ class LocalizerTranslationService:
return translated_str return translated_str
# Use the patched translate() method # Because we don't know when getGlobalTranslationService will be called,
try : # we override the setter to force the use of our patched translate() method.
from Products.Localizer import GlobalTranslationService from Products.PageTemplates import GlobalTranslationService
GlobalTranslationService.translate = LocalizerTranslationService.translate def setGlobalTranslationService(service):
except ImportError: # for Localizer-1.0.1 GlobalTranslationService.translationService = LocalizerTranslationService()
from Products.PageTemplates.GlobalTranslationService import setGlobalTranslationService GlobalTranslationService.setGlobalTranslationService = setGlobalTranslationService
setGlobalTranslationService(LocalizerTranslationService())
# Allow call of translate in python scripts
from Products.Localizer import Localizer from Products.Localizer import Localizer
Localizer.Localizer.translate = LocalizerTranslationService.translate Localizer.Localizer.translate = LocalizerTranslationService.translate
Localizer.Localizer.tranlate__roles__ = None # public Localizer.Localizer.tranlate__roles__ = None # public
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