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): ...@@ -545,7 +545,30 @@ class ListBoxWidget(Widget.Widget):
else: else:
list_action += '&reset=1' list_action += '&reset=1'
object_list = [] 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 # Make sure list_result_item is defined
list_result_item = [] list_result_item = []
...@@ -885,7 +908,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -885,7 +908,7 @@ class ListBoxWidget(Widget.Widget):
select_expression = '' select_expression = ''
if show_stat: if show_stat:
stats = here.portal_selections.getSelectionStats( stats = here.portal_selections.getSelectionStats(
selection_name, selection_name,
REQUEST=REQUEST) REQUEST=REQUEST)
index = 0 index = 0
...@@ -899,7 +922,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -899,7 +922,7 @@ class ListBoxWidget(Widget.Widget):
if (column is not None) and (column[0] == column[1]): if (column is not None) and (column[0] == column[1]):
try: try:
if stats[index] != ' ': if stats[index] != ' ':
select_expression += '%s(%s) AS %s,' % (stats[index], sql, select_expression += '%s(%s) AS %s,' % (stats[index], sql,
alias) alias)
else: else:
select_expression += '\' \' AS %s,' % alias select_expression += '\' \' AS %s,' % alias
...@@ -1185,7 +1208,7 @@ class ListBoxWidget(Widget.Widget): ...@@ -1185,7 +1208,7 @@ class ListBoxWidget(Widget.Widget):
<td nowrap valign="middle" align="center"> <td nowrap valign="middle" align="center">
<select name="list_start" title="%s" size="1" <select name="list_start" title="%s" size="1"
onChange="submitAction(this.form,'%s/portal_selections/setPage')"> onChange="submitAction(this.form,'%s/portal_selections/setPage')">
""" % (portal_url_string, translate('ui', 'Previous Page', default='Previous Page'), """ % (portal_url_string, translate('ui', 'Previous Page', default='Previous Page'),
translate('ui', 'Change Page', default='Change Page'), REQUEST.URL1)) translate('ui', 'Change Page', default='Change Page'), REQUEST.URL1))
for p in range(0, total_pages): for p in range(0, total_pages):
if p == current_page: if p == current_page:
...@@ -1225,18 +1248,18 @@ class ListBoxWidget(Widget.Widget): ...@@ -1225,18 +1248,18 @@ class ListBoxWidget(Widget.Widget):
'selection_name' : selection_name, 'selection_name' : selection_name,
'field_title' : translate('ui', field_title, default = field_title), 'field_title' : translate('ui', field_title, default = field_title),
'pages' : pages, 'pages' : pages,
'record_number' : translate('ui', '${number} record(s)', 'record_number' : translate('ui', '${number} record(s)',
default = '%s record(s)' % total_size, default = '%s record(s)' % total_size,
mapping = { 'number' : str(total_size) }), mapping = { 'number' : str(total_size) }),
'item_number' : translate('ui', '${number} item(s) selected', 'item_number' : translate('ui', '${number} item(s) selected',
default = '%s item(s) selected' % \ default = '%s item(s) selected' % \
len(checked_uids), len(checked_uids),
mapping = { 'number' : \ mapping = { 'number' : \
str(len(checked_uids)) }), str(len(checked_uids)) }),
'flat_list_title': translate('ui', 'Flat List', default='Flat List'), 'flat_list_title': translate('ui', 'Flat List', default='Flat List'),
'report_tree_title': translate('ui', 'Report Tree', 'report_tree_title': translate('ui', 'Report Tree',
default = 'Report Tree'), default = 'Report Tree'),
'domain_tree_title': translate('ui', 'Domain Tree', 'domain_tree_title': translate('ui', 'Domain Tree',
default = 'Domain Tree'), default = 'Domain Tree'),
} }
header_list = [] header_list = []
...@@ -1796,7 +1819,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1796,7 +1819,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
######################################################################### #########################################################################
object_url = None object_url = None
# Try to get a link # Try to get a link
# Check if url_columns defines a method # Check if url_columns defines a method
# to retrieve the URL. # to retrieve the URL.
url_method = None url_method = None
for column in url_columns: for column in url_columns:
...@@ -1810,7 +1833,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1810,7 +1833,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
except (ConflictError, RuntimeError): except (ConflictError, RuntimeError):
raise raise
except: except:
LOG('ListBox', 0, LOG('ListBox', 0,
'Could not evaluate url_method %s' % \ 'Could not evaluate url_method %s' % \
column[1], error=sys.exc_info()) column[1], error=sys.exc_info())
pass pass
...@@ -1955,7 +1978,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')"> ...@@ -1955,7 +1978,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
if render_format == 'list': if render_format == 'list':
#listboxline_list.append(current_listboxline) #listboxline_list.append(current_listboxline)
#LOG('ListBox', 0, 'listboxline_list: %s' % str(listboxline_list) ) #LOG('ListBox', 0, 'listboxline_list: %s' % str(listboxline_list) )
return listboxline_list return listboxline_list
......
...@@ -439,20 +439,19 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -439,20 +439,19 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
# Get the query results # Get the query results
relation_list = portal_catalog(**kw) relation_list = portal_catalog(**kw)
relation_uid_list = map(lambda x: x.uid, relation_list) relation_uid_list = map(lambda x: x.uid, relation_list)
translation_service = getToolByName(field, localizer = getToolByName( field
'translation_service', , 'Localizer'
None) , None
)
N_ = localizer.erp5_ui.gettext
# Prepare a menu # Prepare a menu
if translation_service is not None:
N_ = translation_service.translate
else :
N_ = lambda catalog, msg, **kw:msg
menu_item_list = [('', '')] menu_item_list = [('', '')]
new_object_menu_item_list = [] new_object_menu_item_list = []
for p in portal_type: for p in portal_type:
new_object_menu_item_list += [(N_('ui', 'New ${portal_type}', new_object_menu_item_list += [ ( N_('New %s') % (N_(p))
mapping={'portal_type':N_('ui', p)}), , '%s%s' % (new_content_prefix,p)
'%s%s' % (new_content_prefix,p))] )
]
if len(relation_list) >= MAX_SELECT: if len(relation_list) >= MAX_SELECT:
# If the length is long, raise an error # If the length is long, raise an error
......
...@@ -321,11 +321,11 @@ class RelationStringFieldValidator(Validator.StringValidator): ...@@ -321,11 +321,11 @@ class RelationStringFieldValidator(Validator.StringValidator):
# If the value is different, build a query # If the value is different, build a query
portal_selections = getToolByName(field, 'portal_selections') portal_selections = getToolByName(field, 'portal_selections')
portal_catalog = getToolByName(field, 'portal_catalog') portal_catalog = getToolByName(field, 'portal_catalog')
translation_service = getToolByName(field, 'translation_service', None) localizer = getToolByName( field
if translation_service is not None: , 'Localizer'
N_ = translation_service.translate , None
else : )
N_ = lambda catalog, msg, **kw:msg N_ = localizer.erp5_ui.gettext
# Get the current value # Get the current value
value = Validator.StringValidator.validate(self, field, key, REQUEST) value = Validator.StringValidator.validate(self, field, key, REQUEST)
# If the value is the same as the current field value, do nothing # If the value is the same as the current field value, do nothing
...@@ -384,9 +384,10 @@ class RelationStringFieldValidator(Validator.StringValidator): ...@@ -384,9 +384,10 @@ class RelationStringFieldValidator(Validator.StringValidator):
menu_item_list = [('', '')] menu_item_list = [('', '')]
new_object_menu_item_list = [] new_object_menu_item_list = []
for p in portal_type: for p in portal_type:
new_object_menu_item_list += [(N_('ui', 'New ${portal_type}', new_object_menu_item_list += [ ( N_('New %s') % (N_(p))
mapping={'portal_type':N_('ui', p)}), , '%s%s' % (new_content_prefix,p)
'%s%s' % (new_content_prefix,p))] )
]
# If the length is 1, return uid # If the length is 1, return uid
if len(relation_list) == 1: if len(relation_list) == 1:
relation_uid = relation_uid_list[0] relation_uid = relation_uid_list[0]
......
...@@ -62,7 +62,7 @@ class Getter(Method): ...@@ -62,7 +62,7 @@ class Getter(Method):
class TitleGetter(Method): class TitleGetter(Method):
""" """
Gets the title of the current state Gets the title of the current state
""" """
_need__name__=1 _need__name__=1
# Generic Definition of Method Object # Generic Definition of Method Object
...@@ -92,10 +92,10 @@ class TranslatedGetter(Getter): ...@@ -92,10 +92,10 @@ class TranslatedGetter(Getter):
def __call__(self, instance): def __call__(self, instance):
portal_workflow = getToolByName(instance, 'portal_workflow') portal_workflow = getToolByName(instance, 'portal_workflow')
translation_service = getToolByName(instance, 'translation_service') localizer = getToolByName(instance, 'Localizer')
wf = portal_workflow.getWorkflowById(self._key) wf = portal_workflow.getWorkflowById(self._key)
state_id = wf._getWorkflowStateOf(instance, id_only=1) 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__) psyco.bind(__call__)
...@@ -106,9 +106,9 @@ class TranslatedTitleGetter(TitleGetter): ...@@ -106,9 +106,9 @@ class TranslatedTitleGetter(TitleGetter):
def __call__(self, instance): def __call__(self, instance):
portal_workflow = getToolByName(instance, 'portal_workflow') portal_workflow = getToolByName(instance, 'portal_workflow')
translation_service = getToolByName(instance, 'translation_service') localizer = getToolByName(instance, 'Localizer')
wf = portal_workflow.getWorkflowById(self._key) wf = portal_workflow.getWorkflowById(self._key)
state_title = wf._getWorkflowStateOf(instance).title 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__) psyco.bind(__call__)
...@@ -160,7 +160,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype): ...@@ -160,7 +160,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
if getattr(parent_klass, 'isRADContent', 0) and \ if getattr(parent_klass, 'isRADContent', 0) and \
(ptype != parent_type or klass != parent_klass) and \ (ptype != parent_type or klass != parent_klass) and \
not Base.aq_portal_type.has_key(parent_type): not Base.aq_portal_type.has_key(parent_type):
initializePortalTypeDynamicProperties(parent_object, parent_klass, initializePortalTypeDynamicProperties(parent_object, parent_klass,
parent_type) parent_type)
# Initiatise portal_type properties (XXX) # Initiatise portal_type properties (XXX)
ptype_object = getattr(aq_base(self.portal_types), ptype, None) ptype_object = getattr(aq_base(self.portal_types), ptype, None)
...@@ -170,7 +170,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype): ...@@ -170,7 +170,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
if (ptype_object is not None) and \ if (ptype_object is not None) and \
(ptype_object.meta_type == 'ERP5 Type Information'): (ptype_object.meta_type == 'ERP5 Type Information'):
# Make sure this is an ERP5Type object # Make sure this is an ERP5Type object
ps_list = map(lambda p: getattr(PropertySheet, p, None), ps_list = map(lambda p: getattr(PropertySheet, p, None),
ptype_object.property_sheet_list) ptype_object.property_sheet_list)
ps_list = filter(lambda p: p is not None, ps_list) ps_list = filter(lambda p: p is not None, ps_list)
# Always append the klass.property_sheets to this list (for compatibility) # Always append the klass.property_sheets to this list (for compatibility)
...@@ -184,7 +184,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype): ...@@ -184,7 +184,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
property_sheet_definition_dict = { property_sheet_definition_dict = {
'_properties': prop_list, '_properties': prop_list,
'_categories': cat_list, '_categories': cat_list,
'_constraints': constraint_list '_constraints': constraint_list
} }
for ps_property_name, current_list in \ for ps_property_name, current_list in \
property_sheet_definition_dict.items(): property_sheet_definition_dict.items():
...@@ -193,7 +193,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype): ...@@ -193,7 +193,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
if type(ps_property) in (type(()), type([])): if type(ps_property) in (type(()), type([])):
current_list += ps_property current_list += ps_property
else : else :
raise ValueError, "%s is not a list for %s" % (ps_property_name, raise ValueError, "%s is not a list for %s" % (ps_property_name,
base) base)
if (ptype_object is not None) and \ if (ptype_object is not None) and \
...@@ -339,7 +339,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -339,7 +339,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
isDelivery = 0 # isDelivery = 0 #
isIndexable = 1 # If set to 0, reindexing will not happen (useful for optimization) isIndexable = 1 # If set to 0, reindexing will not happen (useful for optimization)
isPredicate = 0 # isPredicate = 0 #
# Dynamic method acquisition system (code generation) # Dynamic method acquisition system (code generation)
aq_method_generated = {} aq_method_generated = {}
aq_portal_type = {} aq_portal_type = {}
...@@ -481,7 +481,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -481,7 +481,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# Utils # Utils
def _getCategoryTool(self): def _getCategoryTool(self):
return aq_inner(self.getPortalObject().portal_categories) return aq_inner(self.getPortalObject().portal_categories)
def _getTypesTool(self): def _getTypesTool(self):
return aq_inner(self.getPortalObject().portal_types) return aq_inner(self.getPortalObject().portal_types)
...@@ -1164,12 +1164,12 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1164,12 +1164,12 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
return cache[key] return cache[key]
except KeyError: except KeyError:
pass pass
result = self.portal_url.getPortalObject() result = self.portal_url.getPortalObject()
if cache is not None: if cache is not None:
cache[key] = result cache[key] = result
return result return result
security.declareProtected(Permissions.AccessContentsInformation, 'getWorkflowIds') security.declareProtected(Permissions.AccessContentsInformation, 'getWorkflowIds')
...@@ -1351,11 +1351,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1351,11 +1351,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
spec=spec, filter=filter, spec=spec, filter=filter,
portal_type=portal_type, portal_type=portal_type,
strict_membership=strict_membership) strict_membership=strict_membership)
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getRelatedPropertyList' ) 'getRelatedPropertyList' )
getRelatedPropertyList = _getRelatedPropertyList getRelatedPropertyList = _getRelatedPropertyList
security.declareProtected( Permissions.View, 'getValueUids' ) security.declareProtected( Permissions.View, 'getValueUids' )
def getValueUids(self, id, spec=(), filter=None, portal_type=()): def getValueUids(self, id, spec=(), filter=None, portal_type=()):
uid_list = [] uid_list = []
...@@ -1590,9 +1590,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1590,9 +1590,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
security.declareProtected(Permissions.View, 'getTranslatedTitle') security.declareProtected(Permissions.View, 'getTranslatedTitle')
def getTranslatedTitle(self): def getTranslatedTitle(self):
"""Returns the translated title. """ """Returns the translated title. """
translation_service = getToolByName(self, 'translation_service') localizer = getToolByName(self, 'Localizer')
return translation_service.translate('content', return localizer.erp5_content.gettext(unicode(self.getTitle(), 'utf8')).encode('utf8')
unicode(self.getTitle(), 'utf8')).encode('utf8')
# This method allows to sort objects in list is a more reasonable way # This method allows to sort objects in list is a more reasonable way
security.declareProtected(Permissions.View, 'getIntId') security.declareProtected(Permissions.View, 'getIntId')
...@@ -1637,8 +1636,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1637,8 +1636,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
This returns the translated portal_type This returns the translated portal_type
""" """
portal_type = self.portal_type portal_type = self.portal_type
translation_service = getToolByName(self, 'translation_service') localizer = getToolByName(self, 'Localizer')
return translation_service.translate('ui', portal_type).encode('utf8') return localizer.erp5_ui.gettext(portal_type).encode('utf8')
security.declareProtected(Permissions.ModifyPortalContent, 'setPortalType') security.declareProtected(Permissions.ModifyPortalContent, 'setPortalType')
def setPortalType(self, portal_type = None): def setPortalType(self, portal_type = None):
...@@ -1819,8 +1818,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1819,8 +1818,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
Reindexes an object Reindexes an object
args / kw required since we must follow API args / kw required since we must follow API
""" """
self._reindexObject(*args, **kw) self._reindexObject(*args, **kw)
def _reindexObject(self, *args, **kw): def _reindexObject(self, *args, **kw):
# When the activity supports group methods, portal_catalog/catalogObjectList is called instead of # When the activity supports group methods, portal_catalog/catalogObjectList is called instead of
# immediateReindexObject. # immediateReindexObject.
...@@ -1986,18 +1985,18 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -1986,18 +1985,18 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
if script is not None: if script is not None:
return script() return script()
return None return None
def _getAcquireLocalRoles(self): def _getAcquireLocalRoles(self):
""" """
This methods the value of acquire_local_roles of the object's portal_type This methods the value of acquire_local_roles of the object's portal_type
True means, local roles are acquired, which is the standard behavior of True means, local roles are acquired, which is the standard behavior of
Zope objects. False means that the role acquisition chain is cut. Zope objects. False means that the role acquisition chain is cut.
The code to support this is in the user folder. The code to support this is in the user folder.
""" """
def cashed_getAcquireLocalRoles(portal_type): def cashed_getAcquireLocalRoles(portal_type):
return self._getTypesTool()[self.getPortalType()].acquire_local_roles return self._getTypesTool()[self.getPortalType()].acquire_local_roles
cashed_getAcquireLocalRoles = CachingMethod(cashed_getAcquireLocalRoles, id='Base__getAcquireLocalRoles') cashed_getAcquireLocalRoles = CachingMethod(cashed_getAcquireLocalRoles, id='Base__getAcquireLocalRoles')
return cashed_getAcquireLocalRoles(portal_type=self.getPortalType()) return cashed_getAcquireLocalRoles(portal_type=self.getPortalType())
......
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