Commit 91915949 authored by Kevin Deldycke's avatar Kevin Deldycke

Go back to a working version : the version 1.2


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5364 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d66304ee
......@@ -12,20 +12,21 @@
#
##############################################################################
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.
# file in ERP5Form.
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=_marker
, mapping=None, context=None, target_language=None, default=None
, *args, **kw):
"""
This translate() method use Localizer and support catalog aliases.
......@@ -35,14 +36,22 @@ class LocalizerTranslationService:
message_catalog_aliases = { "ui" : "erp5_ui"
, "content": "erp5_content"
}
# Get Localizer
localizer = getToolByName(self, 'Localizer')
localizer = getToolByName(context, 'Localizer')
# Get the Localizer catalog id
catalog_id = message_catalog_aliases.get(domain, domain)
catalog_id = None
if domain in message_catalog_aliases.keys():
catalog_id = message_catalog_aliases[domain]
else:
catalog_id = 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
......@@ -53,15 +62,11 @@ class LocalizerTranslationService:
return translated_str
# Because we don't know when getGlobalTranslationService will be called,
# we override the setter to force the use of our patched translate() method.
# Use the patched translate() method
from Products.PageTemplates import GlobalTranslationService
def setGlobalTranslationService(service):
GlobalTranslationService.translationService = LocalizerTranslationService()
GlobalTranslationService.setGlobalTranslationService = setGlobalTranslationService
# Allow call of translate in python scripts
from Products.Localizer import Localizer
Localizer.Localizer.translate = LocalizerTranslationService.translate
Localizer.Localizer.tranlate__roles__ = None # public
GlobalTranslationService.setGlobalTranslationService = setGlobalTranslationService
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