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 = []
......@@ -885,7 +908,7 @@ class ListBoxWidget(Widget.Widget):
select_expression = ''
if show_stat:
stats = here.portal_selections.getSelectionStats(
selection_name,
selection_name,
REQUEST=REQUEST)
index = 0
......@@ -899,7 +922,7 @@ class ListBoxWidget(Widget.Widget):
if (column is not None) and (column[0] == column[1]):
try:
if stats[index] != ' ':
select_expression += '%s(%s) AS %s,' % (stats[index], sql,
select_expression += '%s(%s) AS %s,' % (stats[index], sql,
alias)
else:
select_expression += '\' \' AS %s,' % alias
......@@ -1185,7 +1208,7 @@ class ListBoxWidget(Widget.Widget):
<td nowrap valign="middle" align="center">
<select name="list_start" title="%s" size="1"
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))
for p in range(0, total_pages):
if p == current_page:
......@@ -1225,18 +1248,18 @@ class ListBoxWidget(Widget.Widget):
'selection_name' : selection_name,
'field_title' : translate('ui', field_title, default = field_title),
'pages' : pages,
'record_number' : translate('ui', '${number} record(s)',
'record_number' : translate('ui', '${number} record(s)',
default = '%s record(s)' % 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' % \
len(checked_uids),
mapping = { 'number' : \
str(len(checked_uids)) }),
'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'),
'domain_tree_title': translate('ui', 'Domain Tree',
'domain_tree_title': translate('ui', 'Domain Tree',
default = 'Domain Tree'),
}
header_list = []
......@@ -1796,7 +1819,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
#########################################################################
object_url = None
# Try to get a link
# Check if url_columns defines a method
# Check if url_columns defines a method
# to retrieve the URL.
url_method = None
for column in url_columns:
......@@ -1810,7 +1833,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
except (ConflictError, RuntimeError):
raise
except:
LOG('ListBox', 0,
LOG('ListBox', 0,
'Could not evaluate url_method %s' % \
column[1], error=sys.exc_info())
pass
......@@ -1955,7 +1978,7 @@ onChange="submitAction(this.form,'%s/portal_selections/setReportRoot')">
if render_format == 'list':
#listboxline_list.append(current_listboxline)
#listboxline_list.append(current_listboxline)
#LOG('ListBox', 0, 'listboxline_list: %s' % str(listboxline_list) )
return listboxline_list
......
......@@ -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]
......
......@@ -62,7 +62,7 @@ class Getter(Method):
class TitleGetter(Method):
"""
Gets the title of the current state
"""
"""
_need__name__=1
# Generic Definition of Method Object
......@@ -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__)
......@@ -160,7 +160,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
if getattr(parent_klass, 'isRADContent', 0) and \
(ptype != parent_type or klass != parent_klass) and \
not Base.aq_portal_type.has_key(parent_type):
initializePortalTypeDynamicProperties(parent_object, parent_klass,
initializePortalTypeDynamicProperties(parent_object, parent_klass,
parent_type)
# Initiatise portal_type properties (XXX)
ptype_object = getattr(aq_base(self.portal_types), ptype, None)
......@@ -170,7 +170,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
if (ptype_object is not None) and \
(ptype_object.meta_type == 'ERP5 Type Information'):
# 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)
ps_list = filter(lambda p: p is not None, ps_list)
# Always append the klass.property_sheets to this list (for compatibility)
......@@ -184,7 +184,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
property_sheet_definition_dict = {
'_properties': prop_list,
'_categories': cat_list,
'_constraints': constraint_list
'_constraints': constraint_list
}
for ps_property_name, current_list in \
property_sheet_definition_dict.items():
......@@ -193,7 +193,7 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
if type(ps_property) in (type(()), type([])):
current_list += ps_property
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)
if (ptype_object is not None) and \
......@@ -339,7 +339,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
isDelivery = 0 #
isIndexable = 1 # If set to 0, reindexing will not happen (useful for optimization)
isPredicate = 0 #
# Dynamic method acquisition system (code generation)
aq_method_generated = {}
aq_portal_type = {}
......@@ -481,7 +481,7 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
# Utils
def _getCategoryTool(self):
return aq_inner(self.getPortalObject().portal_categories)
def _getTypesTool(self):
return aq_inner(self.getPortalObject().portal_types)
......@@ -1164,12 +1164,12 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
return cache[key]
except KeyError:
pass
result = self.portal_url.getPortalObject()
if cache is not None:
cache[key] = result
return result
security.declareProtected(Permissions.AccessContentsInformation, 'getWorkflowIds')
......@@ -1351,11 +1351,11 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
spec=spec, filter=filter,
portal_type=portal_type,
strict_membership=strict_membership)
security.declareProtected( Permissions.AccessContentsInformation,
'getRelatedPropertyList' )
getRelatedPropertyList = _getRelatedPropertyList
security.declareProtected( Permissions.View, 'getValueUids' )
def getValueUids(self, id, spec=(), filter=None, portal_type=()):
uid_list = []
......@@ -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):
......@@ -1819,8 +1818,8 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
Reindexes an object
args / kw required since we must follow API
"""
self._reindexObject(*args, **kw)
self._reindexObject(*args, **kw)
def _reindexObject(self, *args, **kw):
# When the activity supports group methods, portal_catalog/catalogObjectList is called instead of
# immediateReindexObject.
......@@ -1986,18 +1985,18 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
if script is not None:
return script()
return None
def _getAcquireLocalRoles(self):
"""
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
Zope objects. False means that the role acquisition chain is cut.
The code to support this is in the user folder.
"""
def cashed_getAcquireLocalRoles(portal_type):
return self._getTypesTool()[self.getPortalType()].acquire_local_roles
cashed_getAcquireLocalRoles = CachingMethod(cashed_getAcquireLocalRoles, id='Base__getAcquireLocalRoles')
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