Commit 097ca948 authored by Kevin Deldycke's avatar Kevin Deldycke

Use Localizer instead of Translation Service


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5177 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7af83183
......@@ -545,7 +545,30 @@ class ListBoxWidget(Widget.Widget):
else:
list_action += '&reset=1'
object_list = []
translate = portal_object.translation_service.translate
#translate = portal_object.translation_service.translate
# This translate() method has the same prototype as the one defined in Translation Service
global localizer, msg_catalog_binding
localizer = portal_object.Localizer
msg_catalog_binding = { "ui" : "erp5_ui"
, "content": "erp5_content"
}
def translate(domain, msgid, mapping=None, context=None, target_language=None, default=None):
global localizer, msg_catalog_binding
localizer_cat_id = None
if domain in msg_catalog_binding.keys():
localizer_cat_id = msg_catalog_binding[domain]
else:
localizer_cat_id = domain
if localizer_cat_id not in localizer.objectIds():
return msgid
localizer_cat = localizer[localizer_cat_id]
if default == None:
default = []
return localizer_cat.gettext( message = msgid
, lang = None
, default = default
)
# Make sure list_result_item is defined
list_result_item = []
......
......@@ -439,20 +439,19 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
# Get the query results
relation_list = portal_catalog(**kw)
relation_uid_list = map(lambda x: x.uid, relation_list)
translation_service = getToolByName(field,
'translation_service',
None)
localizer = getToolByName( field
, 'Localizer'
, None
)
N_ = localizer.erp5_ui.gettext
# Prepare a menu
if translation_service is not None:
N_ = translation_service.translate
else :
N_ = lambda catalog, msg, **kw:msg
menu_item_list = [('', '')]
new_object_menu_item_list = []
for p in portal_type:
new_object_menu_item_list += [(N_('ui', 'New ${portal_type}',
mapping={'portal_type':N_('ui', p)}),
'%s%s' % (new_content_prefix,p))]
new_object_menu_item_list += [ ( N_('New %s') % (N_(p))
, '%s%s' % (new_content_prefix,p)
)
]
if len(relation_list) >= MAX_SELECT:
# If the length is long, raise an error
......
......@@ -321,11 +321,11 @@ class RelationStringFieldValidator(Validator.StringValidator):
# If the value is different, build a query
portal_selections = getToolByName(field, 'portal_selections')
portal_catalog = getToolByName(field, 'portal_catalog')
translation_service = getToolByName(field, 'translation_service', None)
if translation_service is not None:
N_ = translation_service.translate
else :
N_ = lambda catalog, msg, **kw:msg
localizer = getToolByName( field
, 'Localizer'
, None
)
N_ = localizer.erp5_ui.gettext
# Get the current value
value = Validator.StringValidator.validate(self, field, key, REQUEST)
# If the value is the same as the current field value, do nothing
......@@ -384,9 +384,10 @@ class RelationStringFieldValidator(Validator.StringValidator):
menu_item_list = [('', '')]
new_object_menu_item_list = []
for p in portal_type:
new_object_menu_item_list += [(N_('ui', 'New ${portal_type}',
mapping={'portal_type':N_('ui', p)}),
'%s%s' % (new_content_prefix,p))]
new_object_menu_item_list += [ ( N_('New %s') % (N_(p))
, '%s%s' % (new_content_prefix,p)
)
]
# If the length is 1, return uid
if len(relation_list) == 1:
relation_uid = relation_uid_list[0]
......
......@@ -92,10 +92,10 @@ class TranslatedGetter(Getter):
def __call__(self, instance):
portal_workflow = getToolByName(instance, 'portal_workflow')
translation_service = getToolByName(instance, 'translation_service')
localizer = getToolByName(instance, 'Localizer')
wf = portal_workflow.getWorkflowById(self._key)
state_id = wf._getWorkflowStateOf(instance, id_only=1)
return translation_service.translate('ui', state_id).encode('utf8')
return localizer.erp5_ui.gettext(state_id).encode('utf8')
psyco.bind(__call__)
......@@ -106,9 +106,9 @@ class TranslatedTitleGetter(TitleGetter):
def __call__(self, instance):
portal_workflow = getToolByName(instance, 'portal_workflow')
translation_service = getToolByName(instance, 'translation_service')
localizer = getToolByName(instance, 'Localizer')
wf = portal_workflow.getWorkflowById(self._key)
state_title = wf._getWorkflowStateOf(instance).title
return translation_service.translate('ui', state_title).encode('utf8')
return localizer.erp5_ui.gettext(state_title).encode('utf8')
psyco.bind(__call__)
......@@ -1590,9 +1590,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
security.declareProtected(Permissions.View, 'getTranslatedTitle')
def getTranslatedTitle(self):
"""Returns the translated title. """
translation_service = getToolByName(self, 'translation_service')
return translation_service.translate('content',
unicode(self.getTitle(), 'utf8')).encode('utf8')
localizer = getToolByName(self, 'Localizer')
return localizer.erp5_content.gettext(unicode(self.getTitle(), 'utf8')).encode('utf8')
# This method allows to sort objects in list is a more reasonable way
security.declareProtected(Permissions.View, 'getIntId')
......@@ -1637,8 +1636,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
This returns the translated portal_type
"""
portal_type = self.portal_type
translation_service = getToolByName(self, 'translation_service')
return translation_service.translate('ui', portal_type).encode('utf8')
localizer = getToolByName(self, 'Localizer')
return localizer.erp5_ui.gettext(portal_type).encode('utf8')
security.declareProtected(Permissions.ModifyPortalContent, 'setPortalType')
def setPortalType(self, portal_type = None):
......
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